码迷,mamicode.com
首页 > 其他好文 > 详细

xamarin.form RelativeLayout

时间:2018-11-28 12:26:13      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:ESS   高度   ntp   设置   nta   page   位置   etop   htc   

<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

标签:ESS   高度   ntp   设置   nta   page   位置   etop   htc   

原文地址:https://www.cnblogs.com/jiecaoge/p/10029965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!