我需要在相对布局中添加视图。Xamarin Forms-相对布局 - 将第一个视图的顶部对齐到第二个底部而不在垂直堆叠布局中添加它们
我需要将它们相对于彼此的边缘垂直/水平对齐。不关于父视图。
但似乎Xamarin相对布局API只能提供相对于父RelativeToParent
的布局对齐。
我需要在相对布局中添加视图。Xamarin Forms-相对布局 - 将第一个视图的顶部对齐到第二个底部而不在垂直堆叠布局中添加它们
我需要将它们相对于彼此的边缘垂直/水平对齐。不关于父视图。
但似乎Xamarin相对布局API只能提供相对于父RelativeToParent
的布局对齐。
xamarin形式做支持RelativeToView
<RelativeLayout>
<BoxView x:Name="topBox"
Color="Red"
RelativeLayout.WidthConstraint ="{ConstraintExpression
Type=RelativeToParent,
Property=Width,
Factor=0.6,
Constant=0}"
RelativeLayout.XConstraint ="{ConstraintExpression
Type=RelativeToParent,
Property=X,
Constant=20}" />
<BoxView
Color="Blue"
RelativeLayout.WidthConstraint ="{ConstraintExpression
Type=RelativeToParent,
Property=Width,
Factor=0.6,
Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression
Type=RelativeToView,
ElementName=topBox,
Property=Y,
Constant=40}"
RelativeLayout.XConstraint="{ConstraintExpression
Type=RelativeToView,
ElementName=topBox,
Property=X,
Constant=0}" />
</RelativeLayout>
希望它可以帮助
由于Kojan指出,有Constraint.RelativeToView
。
对于XAML和C#示例,请查看: https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints