I have some very weird placement of controls with absoluteLayout. The whole thing looks buggy to me actually. Instead of giving an example from my own code, please see this page: https://adventuresinxamarinforms.com/2015/05/05/demystifying-xamarin-forms-absolutelayout-and-relativelayout-positioning/
From that page, it's this portion that perfectly explains my question:
Oh dear! That’s not what I expected. The BoxView is offset so that it falls short of the correct x and y positions. Why has this happened? It took me a while to wrap my head around this but essentially the AbsoluteLayout also takes into account the size of the control when calculating the relative x and y position. In other words it is 25% of the AbsoluteLayout less the size of the control. Why would it do this? That’s a good question.>
It boils down to this. The box generated from these 2 separate ways of placing color on a form should be in the exact same position but they are not:
The red box is correct:
<Grid RowSpacing="0" ColumnSpacing="0"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <BoxView Grid.Row="1" Grid.Column="1" BackgroundColor="Red" /> </Grid>
This yellow box is not correct:
<AbsoluteLayout Opacity="0.75"> <BoxView Color="Yellow" AbsoluteLayout.LayoutBounds="0.25,0.25,0.25,0.25" AbsoluteLayout.LayoutFlags="All" /> </AbsoluteLayout>
I think there must be a bug with AbsoluteLayout. Does anyone agree?
Thanks for your help.