我需要在相对布局中添加视图。
我需要将它们相对于彼此的边缘垂直/水平对齐。与父视图无关。
但似乎Xamarin相对布局API只能提供相对于父RelativeToParent
的相对布局对齐。
答案 0 :(得分:1)
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>
希望有所帮助
答案 1 :(得分:0)
Kojan指出,Constraint.RelativeToView
。
对于XAML和C#示例,请查看: https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints