2

I have a RecyclerView matching the height of the parent layout.

I need to have an item there to function as a footer. Doing this is not the problem when there are a bunch of items in the list.

The problem is to get it to stick to the bottom when there are a few items and it's not enough to enable the scroll. So, if I have, say 1 item plus footer item, how can I display this item at the bottom of the RecyclerView?

hpinhal
  • 512
  • 6
  • 22
  • What about wraping it all in a `RelativeLayout`? – Sunshinator Dec 16 '16 at 15:22
  • better way, to create footer in your adapter like this http://stackoverflow.com/a/29168617/6110027 – Serega Gevelev Dec 16 '16 at 15:37
  • I have an adapter like that, but if there are no normal items or only a few, the footer will not be at the bottom of the list. – hpinhal Dec 16 '16 at 15:58
  • I'm currently needing to do the same - did you find an easy solution? I'm thinking about the logic that the "sticky header" devs use, but imagining that that is stuck to the bottom instead of the top – kassim Oct 29 '17 at 23:50
  • did you find anything? – Archie G. Quiñones Jan 02 '19 at 01:30
  • Best way was to create an ItemDecorator to create that blank space between your views and footer. You can use the **estimated items height** for your calculations. If all items in your list have the same height, the calculations will be accurate, otherwise you have get a bit more or less space than you'd need. – hpinhal Jan 02 '19 at 10:22

2 Answers2

0

Try using android:weight property. Or if you're using RelativeLayout align the footer to the bottom of the parent view

Sav
  • 23
  • 4
  • This will always show in the bottom of the recycler view but will not scroll with it if the list has plenty of items. – hpinhal Dec 16 '16 at 15:57
0

try this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/places_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

<YourView
   android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>

YourView is the view where you will actually add the view for your funcionality. Even if there is no items or there is, it will always be on bottom.

Miljan Vulovic
  • 1,586
  • 3
  • 20
  • 48
  • This will always show in the bottom of the recycler view but will not scroll with it if the list has plenty of items. – hpinhal Dec 16 '16 at 15:57
  • Why not just add last item to be your custom item, return different viewtype in your recycler view and it will then show as the last item always? – Miljan Vulovic Dec 16 '16 at 15:58
  • It's how it currently is, but imagine where there's only one item. This footer item will be below that but not at the bottom. Should be a spacing there. – hpinhal Dec 16 '16 at 15:59