xamarin.form RelativeLayout

Posted jiecaoge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xamarin.form RelativeLayout相关的知识,希望对你有一定的参考价值。

<ContentPage.Content>
        <RelativeLayout>
            <BoxView Color="Red"
                     RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.15,Constant=0}"
                     RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.15,Constant=0}"
                     RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.7,Constant=0}"
                     RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.7,Constant=0}"
                     >
                
            </BoxView>
        </RelativeLayout>
    </ContentPage.Content>

  可以设置4个属性YConstraint,XConstraint,HeightConstraint,WidthConstraint

  其中Contant是按照像素点偏移的值,Type是针对哪个控件的偏移有RelativeToParent和RelativeToView,ElementName是针对哪个控件做偏移只有在ReleativeToView的时候用到,Property是针对控件的哪个属性做偏移,

ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.15,Constant=0的意思是针对上层元素的高度,用高度*0.15+0的实际位置
            BoxView b = new BoxView() { BackgroundColor = Color.Red };

            relative1.Children.Add(b
                , Constraint.RelativeToParent((parent) =>
                {
                    return parent.X * 0.5;
                })
            , Constraint.RelativeToParent((parent) =>
            {
                return parent.Y * 0.5;
            })
            , Constraint.RelativeToParent((parent) =>
            {
                return parent.X * 0.5;
            })
            , Constraint.RelativeToParent((parent) =>
            {
                return parent.X * 0.5;
            })
             );

  

以上是关于xamarin.form RelativeLayout的主要内容,如果未能解决你的问题,请参考以下文章

Xamarin.Form 蓝牙ble

Xamarin.Form 初学 之 服务引用-WCF服务引用

Xamarin.Form指纹认证

xamarin.form MasterDetailPage

xamarin.form RelativeLayout

xamarin.form scrollView