Reputation: 13
how can i add spacing below the last element of a RecyclerView, where the height of the spacing is exactly as high as the height of the RecyclerView - so that I can scroll to the bottom of the RecyclerView and the last element is displayed at the top of the RecyclerView?
Basically I want to be able to keep scrolling until the last element of my RecyclerView is displayed at the very top:
+------------+ +------------+
| 1. element | | 5. element |
| 2. element | | |
| 3. element | | |
| 4. element | | |
| 5. element | | |
+------------+ +------------+
I found solutions where I add a fixed padding to the RecyclerView with the attribute cliptopadding=false:
android:padding="4dp"
android:clipToPadding="false"
However this only adds a fixed dp of padding. And since I don't know the height of my RecyclerView I cannot use a fixed padding of xx dp.
How can I achieve the desired behavior?
Upvotes: 1
Views: 381
Reputation: 652
You could detect the last item in the list and when you bind data to it you also set its bottom margin to the lists height - the item height.
Upvotes: 0