Window.ClientBounds returning wrong resolution on Android

I am setting the PreferredBackBuffer to Window.ClientBounds in the Initialization step then applying the changes to the GraphicsDeviceManager.

However when I draw a texture on screen there will be blank bars where the image doesn’t get drawn on the left and right of the screen.

If I add +50 to the PreferredBackBufferWidth the problem gets fixed but this is a very bad solution obviously. I’m not sure why Window.ClientBounds width and height doesn’t return the real resolution of the device?

edit: so I checked my phone’s resolution and the height is wrong too.
OnePlus 7 resolution: 1080 x 2340 pixels
Resolution returned by ClientBounds = 1043 x 2260

edit2: solved the problem, have to add this to Activity.cs:

    Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
    Window.AddFlags(WindowManagerFlags.Fullscreen);
    Window.AddFlags(WindowManagerFlags.LayoutInOverscan);
1 Like

Could be the bar with the softbuttons on android - they are there, when the game gets initialized but are gone when the view is actually displaying … at least I remember some sort of such problem.

I do not remember my exact solution to that, but I think it was implementing the resize mechanics by recreating the backbuffer on window resize

That’s indeed the case. Android platform does no longer update when the client size change. Additionally the events OrientationChanged and ClientSizeChanged are no longer fired.
The last version that this worked was 3.5, for some reason MG stripped the entire XNA-compatible functionality of window resizing/orientation handling in order to support user enforced orientation.

For example that’s the code that needs to be there to update the backbuffer.
You can use my nuget build that has all of my changes.