Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add margins to a RecyclerView for the last element?

I several screens that use RecyclerView and also has a small Fragment that is on top of the RecyclerView. When that Fragment is displayed I'd like to make sure I can scroll to the bottom of the RecyclerView. The Fragment isn't always displayed. If I used margins on the RecyclerView I'd need to dynamically remove and add them when the Fragment is displayed. I could add margins onto the last item in the list, but that is also complicated and if I load more things later (ie pagination) I'd have to strip off those margins again.

How would I dynamically add or remove margins to the view? What are some other options to solve this?

like image 349
chubbsondubs Avatar asked May 03 '16 18:05

chubbsondubs


People also ask

What does notifyDataSetChanged do in RecyclerView?

notifyDataSetChanged. Notify any registered observers that the data set has changed. There are two different classes of data change events, item changes and structural changes. Item changes are when a single item has its data updated but no positional changes have occurred.

What is LayoutManager in RecyclerView?

This wear-specific implementation of LinearLayoutManager provides basic offsetting logic for updating child layout. A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.


1 Answers

So if you want to add some padding at the bottom of your RecyclerView you can set the paddingBottom and then clipToPadding to false. Here's an example

<android.support.v7.widget.RecyclerView     android:id="@+id/my_list"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:clipToPadding="false"     android:paddingBottom="100dp" /> 
like image 194
Reaz Murshed Avatar answered Sep 18 '22 19:09

Reaz Murshed