How to add a simple 8dp header/footer to Android's RecyclerView?
Adding a top padding and setting clipToPadding
to false will do the trick.
Something like this:
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:paddingTop="8dp"
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="match_parent" />
If you are using a RecyclerView with a layout_weight
, and paddingBottom
is not working for you, making sure you set the layout_height to 0dp
! Otherwise, strangely, paddingTop works but paddingBottom does not:
<android.support.v7.widget.RecyclerView android:id="@+id/recycler"
android:paddingBottom="20dp"
android:clipToPadding="false"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />