相对布局 XConstraint & YConstraint 对比。 Xamarin.Forms 中的 WidthConstraint 和 HeightConstraint
Relative Layout XConstraint & YConstraint Vs. WidthConstraint & HeightConstraint in Xamarin.Forms
在Xamarin.Forms中使用相对布局时,XConstraint 和 WidthConstraint 或 YConstraint 和 HeightConstraint 有什么区别?
看起来它们都有相同的用途,并且可以互换使用。这是 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(垂直)位置
WidthConstraint
– 决定视图的宽度
HeightConstraint
– 决定视图的高度
这些值中的每一个都设置为 RelativeLayout 中的比例值。
在Xamarin.Forms中使用相对布局时,XConstraint 和 WidthConstraint 或 YConstraint 和 HeightConstraint 有什么区别?
看起来它们都有相同的用途,并且可以互换使用。这是 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(垂直)位置
WidthConstraint
– 决定视图的宽度
HeightConstraint
– 决定视图的高度
这些值中的每一个都设置为 RelativeLayout 中的比例值。