Xaml 相对布局XConstraint&;Y约束与宽度约束&;Xamarin.Forms中的高度约束
在Xamarin.Forms中使用相对布局时,XConstraint和WidthConstraint或YConstraint和HeightConstraint有什么区别?Xaml 相对布局XConstraint&;Y约束与宽度约束&;Xamarin.Forms中的高度约束,xaml,xamarin.forms,android-relativelayout,Xaml,Xamarin.forms,Android Relativelayout,在Xamarin.Forms中使用相对布局时,XConstraint和WidthConstraint或YConstraint和HeightConstraint有什么区别? 似乎它们都有相同的用途,可以互换使用。以下是Microsoft文档中的一个示例。 <RelativeLayout> <BoxView Color="Red" x:Name="redBox" RelativeLayout.YConstraint="{Co
似乎它们都有相同的用途,可以互换使用。以下是Microsoft文档中的一个示例。
<RelativeLayout>
<BoxView Color="Red" x:Name="redBox"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,Factor=.15,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=1,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Height,Factor=.8,Constant=0}" />
<BoxView Color="Blue"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=redBox,Property=Y,Factor=1,Constant=20}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=redBox,Property=X,Factor=1,Constant=20}"
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Factor=.5,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Height,Factor=.5,Constant=0}" />
</RelativeLayout>
不,它们是不同的
XConstraint
–确定视图锚点的x(水平)位置
YConstraint
–确定视图锚点的y(垂直)位置
宽度约束
–确定视图的宽度
高度约束
–确定视图的高度
这些值中的每一个都设置为中的比例值。我的解决方案对您有用吗?如果是,请您接受(单击☑️ 在这个答案的左上角),这样我们就可以帮助更多有同样问题的人:)。