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

Aneetha 65 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,578 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,056 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.