Fixed
Status Update
Comments
ad...@google.com <ad...@google.com>
tn...@google.com <tn...@google.com>
tn...@google.com <tn...@google.com> #2
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
-
Are you reporting this as a Developer or User?
-
Please confirm if you are using any third party application as a launcher?
-
Could you please provide a screen record of the issue for us to further investigate?
Note: Please upload the files to google drive and share the folder to
an...@google.com <an...@google.com> #3
- I am a User
- No third party launcher using Default pixel launcher
- I cannot for now recreate the bug but will enable screen record and upload when caught
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.