Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Expand one content view while the other content view is with fixed height in Xamarin Forms

enter image description hereI have two content views one after the other, were one view is with fixed height and the other view should fill and expand the parent view. I have tried the following things :

Using 2 content view inside a StackLayout, with vertical options as "End".

    <StackLayout Orientation="Vertical" VerticalOptions="End" Spacing="0" >
   <ContentView  x:Name="red_ContentView" BackgroundColor="Red" VerticalOptions="FillAndExpand">
        </ContentView>
        <ContentView x:Name="blue_ContentView" BackgroundColor="Blue" HeightRequest="66">
        </ContentView>
</StackLayout>

I want the white space in the image to be filled with red_ContentView.

like image 979
MEGHANA S Avatar asked Dec 05 '25 16:12

MEGHANA S


1 Answers

As noted above, using VerticalOptions="FillAndExpand" on the StackLayout might get you what you want.

An alternative is to use Grid instead of StackLayout, something like this:

<Grid VerticalOptions="FillAndExpand">
   <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="66"/>
   </Grid.RowDefinitions>

   <ContentView  x:Name="red_ContentView" BackgroundColor="Red" Grid.Row="0">
   </ContentView>

   <ContentView x:Name="blue_ContentView" BackgroundColor="Blue" Grid.Row="1">
   </ContentView>
</Grid>
like image 71
DavidS Avatar answered Dec 08 '25 11:12

DavidS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!