xamlxamarinlayout

Xamarin: Grid in AbsoluteLayout not fill screen


I have an absolutLayout containing a grid. The absoluteLayout, as seen from the image, correctly fills the screen horizontally. The issue seems to be the grid, which is not drawn for the entire horizontal length of the screen, leaving an empty section. If I try to move the grid outside the absoluteLayout, the grid correctly fills the screen horizontally, so I think the problem is related to the absoluteLayout + grid combination. I know very little about absoluteLayouts and I don't understand how to solve this issue.

enter image description here

Xaml (to make it easy I have omitted the code for drawing the elements contained in the grid):

            <AbsoluteLayout BackgroundColor="Red">
            <Grid x:Name="GridDettaglio" Padding="4,2" ColumnSpacing="1" BackgroundColor="Aqua" HorizontalOptions="Fill" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70"/>    <!--0-->
                    <ColumnDefinition Width="30"/>    <!--1-->
                    <ColumnDefinition Width="70"/>    <!--2-->
                    <ColumnDefinition Width="40"/>    <!--3-->
                    <ColumnDefinition Width="70"/>    <!--4-->
                    <ColumnDefinition Width="30"/>    <!--5-->
                    <ColumnDefinition Width="*"/>     <!--6-->
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/> 
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
              
            </Grid>
        </AbsoluteLayout>

Solution

  • I am not sure why are you using absolutelayout, but for it to fill the screen you usually don't need to give it anything. But since it's not doing it on its own, just give it the flags and bounds like below:

    <Grid AbsoluteLayout.LayoutBounds="0,0,1,1"
                 AbsoluteLayout.LayoutFlags="All"