MAUI .NET 8 - Absolute layout height size is not same as in Portrait and Landscape mode.

Aneetha 45 Reputation points
2024-07-19T12:20:35.6566667+00:00

In my MAUI project, I used AbsoluteLayout to define a UI design. However, I found that AbsoluteLayout height proportional is not the same as in Portrait and Landscape.

The height size differs, For example,

In Portrait mode,

Screenshot 2024-07-19 at 5.39.59 PM

In Landscape mode,

Screenshot 2024-07-19 at 5.39.46 PM

I define a height as below,



protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
screenWidth = width;
screenHeight = height;
double lytheight = screenHeight * 0.10;
AbsoluteLayout.SetLayoutBounds(stkNavigationBar, new Rect(0, 0,width,lytheight)); 
}

10% of the screen height I gave to the layout, but in landscape mode, the height size is small when comparing portrait mode.

is there any way to make the height size is same in both portrait and landscape mode?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,206 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,266 Reputation points
    2024-07-19T17:19:29.0066667+00:00

    That would be a fixed height rather than %. You could also do a % of the larger of width and height.

    0 comments No comments