sgarcia.dev
sgarcia.dev

Reputation: 6170

XamarinForms: StackLayout inside RelativeLayout is not filling the whole screen

I have this:

<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
                <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"></StackLayout>
</RelativeLayout>

But for some reason, even tough the RelativeLayout clearly expands, the StackLayout doesn't. How can I get the StackLayout to stretch horizontally and fill the whole width/height of the screen?

Upvotes: 19

Views: 10601

Answers (1)

Art
Art

Reputation: 3167

For RelativeLayout you will need to use constraints instead of Vertical/Horizontal options. Should be something like

<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"
     RelativeLayout.WidthConstraint=
         "{ConstraintExpression Type=RelativeToParent,
                                Property=Width,
                                Factor=1}"
     RelativeLayout.HeightConstraint=
         "{ConstraintExpression Type=RelativeToParent,
                                Property=Height,
                                Factor=1}">
</StackLayout>

Upvotes: 41

Related Questions