Reputation: 2824
I need to add views in a relative layout.
I need to align them vertically/ horizontally with respect to each other's edges. Not with respect to the parent view.
But it seems that the Xamarin relative layout API can only provide relative layout alignments with respect to the parent RelativeToParent
.
Upvotes: 1
Views: 1341
Reputation: 1494
As Kojan points out, there is Constraint.RelativeToView
.
For XAML and C# examples, check out: https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints
Upvotes: 0
Reputation: 289
xamarin forms do support 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>
Hope it helps
Upvotes: 1