Philipp Schumann Philipp Schumann - 1 year ago 135
Android Question

How to add a simple 8dp header/footer to Android's RecyclerView?

Is there a way to add a simple header/footer to a RecyclerView?

Here you can see what I've got. The first Card touches the Toolbar
This is what I've got

And here you can see what I want. 8dp Padding between the bottom and the Card.
This is what I want to have

Methods I tried so far:

  • Use a header view in my recyclerview. But I think it is very unefficient to do this for every recyclerview.

  • use a 8dp top margin which results in the problem that the recyclerview has white bars on top/bottom when scrolling.

  • add a padding to the list item which results in different margins between the outer and inner cards.

  • I'm sure that there is a simple solution which I don't know so far.

    Answer Source

    Adding a top padding and setting clipToPadding to false will do the trick.
    Something like this:

        android:layout_height="match_parent" />
    Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download