Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 723
sgarcia.dev Avatar asked May 19 '15 22:05

sgarcia.dev


1 Answers

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>
like image 120
Artur Shamsutdinov Avatar answered Nov 13 '22 21:11

Artur Shamsutdinov