Fixed
Status Update
Comments
ad...@google.com <ad...@google.com>
tn...@google.com <tn...@google.com>
an...@google.com <an...@google.com> #3
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Meerkat | 2024.3.1 Canary 7
- Android Gradle Plugin 8.9.0-alpha07
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
Description: When using android:fitsSystemWindows="true" in a layout (e.g., RelativeLayout), it prevents the application of custom padding directly on that layout. As a result, developers are forced to wrap the layout with another layout to allow both the system window insets and custom padding to be applied correctly. The Android Lint tool incorrectly flags the outer layout as unnecessary when using this pattern, which is misleading.
Lint Warning: This RelativeLayout layout or its FrameLayout parent is unnecessary.
A layout with children that has no siblings, is not a ScrollView or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy. Issue id: UselessParent Vendor: Android Open Source Project
Steps to Reproduce: Define a RelativeLayout or other layout with android:fitsSystemWindows="true":
Add custom padding on the same layout:
Notice that the custom padding is ignored because of the fitsSystemWindows attribute. To make both system window insets and custom padding work, you must wrap the RelativeLayout in another layout (e.g., FrameLayout):
Run Lint to check for warnings. Observe that Lint flags the outer FrameLayout as unnecessary, suggesting it can be removed.
Expected Behavior: The Lint tool should not flag the outer FrameLayout or RelativeLayout as unnecessary when it is required to allow both system window insets (via fitsSystemWindows) and custom padding to be applied correctly. Please note that this has nothing to do with my RelativeLayout not having children that use alignment tags - my children do have those tags.
Actual Behavior: The Lint tool incorrectly issues the UselessParent warning, suggesting that the parent layout can be removed, which would break the intended functionality.
Justification: The combination of android:fitsSystemWindows="true" and custom padding cannot be applied within the same layout. This forces developers to use two nested layouts: one for system insets and the other for custom padding. The Lint tool incorrectly flags the necessary outer layout as superfluous, misleading and incorrect for this use case.
Note:
Oddly, given the same need to have fitSystemsWindows=true as well as custom padding, if you use 2 nested FrameLayout for the same purpose, you do not get this lint error which is a good thing of course, but is not consistent with the case of a FrameLayout that wraps a RelativeLayout.
This configuration does not report the lint error which in my opinion is the correct behaviour.
Conclusion: The Lint warning should be updated to properly handle scenarios where fitsSystemWindows is used with custom padding. Flattening the hierarchy in such cases would break the intended behaviour of the layout, and the tool should not incorrectly flag the parent layout as unnecessary.