Skip to content

[Android] CollectionView items get incorrect padding after screen rotation when using SetOnApplyWindowInsetsListener on Android 15+ #33421

@YukiNuno12

Description

@YukiNuno12

Description

When using ViewCompat.SetOnApplyWindowInsetsListener for Edge-to-Edge support on Android 15+ devices, CollectionView items inside a NavigationPage receive incorrect padding after rotating the screen from landscape to portrait orientation.
The padding size matches the DisplayCutout insets value (e.g., 118px). When scrolling, items that are redrawn after going off-screen display correctly without the extra padding.
The WindowInsetsHandler sets correct padding values (confirmed via debug logs), and returns WindowInsetsCompat.Consumed, but the CollectionView items still receive incorrect padding.

Steps to Reproduce

  1. Create a MAUI app targeting Android 15+ (API 35+)
  2. Use NavigationPage as the root page structure
  3. Add a CollectionView with multiple items to a page
  4. In MainActivity.OnCreate, add the following Edge-to-Edge setup
if (Build.VERSION.SdkInt >= BuildVersionCodes.VanillaIceCream)
{
    WindowCompat.SetDecorFitsSystemWindows(Window, false);
    ViewCompat.SetOnApplyWindowInsetsListener(Window.DecorView, new WindowInsetsHandler());
}

5.Implement WindowInsetsHandler

csharppublic class WindowInsetsHandler : Java.Lang.Object, IOnApplyWindowInsetsListener
{
    public WindowInsetsCompat OnApplyWindowInsets(View view, WindowInsetsCompat insets)
    {
        var systemBars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
        view.SetPadding(systemBars.Left, systemBars.Top, systemBars.Right, systemBars.Bottom);
        return WindowInsetsCompat.Consumed;
    }
}
  1. Run the app on an Android 15+ device with a display cutout (notch)
  2. Rotate the device: Portrait → Landscape → Portrait
  3. Expected: CollectionView items display correctly without extra padding
  4. Actual: CollectionView items have incorrect padding on the right side (matching DisplayCutout insets size)

Version with bug

10.0.1 (MAUI 10.0.11)

Is this a regression from previous behavior?

Yes, this worked in .NET 9 / MAUI 9

Last version that worked well

9.0.x (MAUI 9)

Affected platforms

Android

Affected platform versions

Android 15 (API 35) and above

Did you find any workaround?

Removing ViewCompat.SetOnApplyWindowInsetsListener prevents this issue, but then Edge-to-Edge support cannot be properly implemented for Android 15+ devices.

Relevant log output

[WindowInsets] Rotation: Rotation90
[WindowInsets] SystemBars: L=0, T=74, R=0, B=63
[WindowInsets] DisplayCutout: L=118, T=0, R=0, B=0
[WindowInsets] Applied Padding: L=118, T=74, R=0, B=63

[WindowInsets] Rotation: Rotation0
[WindowInsets] SystemBars: L=0, T=118, R=0, B=63
[WindowInsets] DisplayCutout: L=0, T=118, R=0, B=0
[WindowInsets] Applied Padding: L=0, T=118, R=0, B=63

Note: Even though Applied Padding: L=0 is set correctly when returning to portrait, CollectionView items still show incorrect padding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewplatform/androids/no-reproCan no longer be reproduced on latests/triagedIssue has been revieweds/try-latest-versionPlease try to reproduce the potential issue on the latest public versiont/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions