7vikram7
7vikram7

Reputation: 2824

Xamarin Forms- Relative Layout- Align Top of 1st View to Bottom of 2nd without adding them in a Vertical StackLayout

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

Answers (2)

Shazbot
Shazbot

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

kojan abzah
kojan abzah

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>

enter image description here

Hope it helps

Upvotes: 1

Related Questions