I've got a page in my Xamarin.Forms project that I need to look something like this:
I can position the red and blue boxes, no problem. But I can't figure out how to create the green one.
The XAML I use is the following:
<StackLayout HorizontalOptions="FillAndExpand">
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="Red">
//I'm thinking the green box should be positioned absolutely in here or something?
</StackLayout>
<StackLayout VerticalOptions="End" BackgroundColor="Blue">
<Grid VerticalOptions="EndAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Text="Button" HorizontalOptions="FillAndExpand" BorderRadius="0" VerticalOptions="EndAndExpand" HeightRequest="50" TextColor="White" BackgroundColor="#85C034"></Button>
</Grid>
</StackLayout>
</StackLayout>
The Grid
is the best layout control to implement this behaviour. You can use *
to expand a row out to fill, nest the text label inside a content view in the first row and then set the second row to the desired height.
EG:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Grids"
x:Class="Grids.GridsPage">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<ContentView
BackgroundColor="Red" Grid.Row="0">
<Label TextColor="Black"
Text="Text"
Margin="0,0,0,10"
BackgroundColor="#00FF02"
VerticalOptions="End"
HorizontalOptions="Center"/>
</ContentView>
<ContentView BackgroundColor="Blue" Grid.Row="1"/>
</Grid>
</ContentPage>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With