我需要在相对布局中添加视图 .
我需要将它们相对于彼此的边缘垂直/水平对齐 . 不是关于父视图 .
但似乎Xamarin相对布局API只能提供相对于父 RelativeToParent 的相对布局对齐 .
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 .
Constraint.RelativeToView
对于XAML和C#示例,请查看:https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints
2 回答
xamarin表单支持RelativeToView
希望能帮助到你
正如Kojan指出的那样,有
Constraint.RelativeToView
.对于XAML和C#示例,请查看:https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints