Android what does the clipToPadding Attribute do?
You can use clipToPadding for views that scroll. Say you have a listview for example and you having padding set on the top and bottom. Normally the padding is visible no matter which items are visible on the screen. The diagram below represents a list with 10 items but only 4 are visible on screen, with default clipToPadding settings:
- (padding)
- item 4
- item 5
- item 6
- item 7
- (padding)
Now if you were to set clipToPadding="false"
instead of just being applied normally to the entire view it only applies the padding to the end items, this is what you'd see in the same scenario:
- item 4
- item 5
- item 6
- item 7
Now if you were to scroll to the top or bottom of the list, this is what you would see:
- (padding)
- item 1
- item 2
- item 3
- item 4
OR
- item 7
- item 8
- item 9
- item 10
- (padding)
A practical usage for this is if you have a Floating Action Button for example, you should use clipToPadding combined with bottom padding to ensure the entirety of the bottom item can be seen without being obstructed by the FAB.
Does that make sense?
When using clipToPadding in ListView's the items get recycled prematurely
Clip to padding is the default behavior. Having the view recycled as soon as it's not visible (i.e. past the padding) is the normal and expected behavior.
Are you sure you're not trying to set clipToPadding
to false
? In that case, ListView will still recycle its children as soon as they enter the padding area. The attribute clipToPadding
only affects drawing and is not taken into account by layout algorithms such as ListView
's. We could fix this behavior in a future version of the platform but that won't help you right now, sorry :(
RecyclerView clipToPadding = false
This is a known bug, will be fixed when RecyclerView is released.
Jetpack Compose ClipToPadding
Try content padding like below:
LazyColumn(
contentPadding = PaddingValues(bottom=10.dp),
){
items(items.size) { index ->
EmergencyContactComposeItem(emergencyContact = items[index])
}
}
Android: clipToPadding in LinearLayout with child ListView ignored?
The ListView should have the clipToPadding property instead of the LinearLayout (and it should also contain the padding rather than the LinearLayout with the scrollbarStyle="outsideOverlay property so that the scrollbar can be placed in the margins of the app). See the Source for more information:
<ListView
…
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
Source
Android: RecyclerView padding preventing full screen experience
Set android:clipToPadding="false"
on your RecyclerView.
That will allow the paddingTop (and bottom, if you want), to be part of the scrollable part.
A better description is found here:
Android what does the clipToPadding Attribute do?
Overscroll scrolling indicators with clip to padding
I believe those white lines you're seeing are the fadingEdge
of the ListView
. You can get rid of them by adding this attribute to your ListView
in xml:
android:fadingEdge="none"
or in code:
listview.setVerticalFadingEdgeEnabled(false);
In ICS and forward, fading edges are disabled by default which is why you don't see them.
Can't get clipChildren=false attribute to work
Also set
android:clipToPadding="false"
Beside:
android:clipChildren="false"
Related Topics
Local Image Caching Solution for Android: Square Picasso, Universal Image Loader, Glide, Fresco
How to Programmatically Set the Layout_Align_Parent_Right Attribute of a Button in Relative Layout
"Unable to Locate Adb" Using Android Studio
Access the Http Response Headers in a Webview
Bind Service to Activity in Android
Mediacodec and Camera: Colorspaces Don't Match
Why Is Android Studio Reporting "Uri Is Not Registered"
How to Make an Android App to Always Run in Background
Best Way to Have Paid and Free Version of an Android App
How to Size an Android View Based on Its Parent's Dimensions
Android: How to Convert String to Date
Android - Set Text to Textview
Scan_Results_Available_Action Return Empty List in Android 6.0
Bitmap Recycle with Largeheap Enabled
Android Studio - Unable to Merge from Svn Branch
Android Failed to Load Js Bundle
Invoke-Customs Are Only Supported Starting with Android 0 --Min-API 26