6

I'm using a recyclerview and have a FAB on my layout. I want to be able to give a bit of space at the bottom of the last item much like the Gmail app does so when you scroll to the bottom the right hand star on the bottom item is still clickable.

I tried adding some padding to the bottom which achieves this but the scrollbar doesn't scroll all the way to the bottom, stopping at the padding height, whilst the Gmail version does. Does anyone have any idea how to do this?

<RecyclerView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:paddingBottom="90dp"
    android:scrollbars="vertical" />
CodeChimp
  • 4,277
  • 6
  • 39
  • 52

3 Answers3

6

you have to add "footer" at the end of your adapter. This footer will be just a blank view, like a android.widget.Space.

recycler view doesn't have any native options for header n footers, but you can google around and find a few options.

I developed a library with extras for recycler view that have header/footer/section options:

I didn't upload it yet to Maven but you can grab the code here: https://github.com/eyeem/RecyclerViewTools

then to use is just:

WrapAdapter wrapAdapter = new WrapAdapter(adapter);
wrapAdapter.addFooter(inflater.inflate(R.layout.footer, recycler,   false));
recycler.setAdapter(wrapAdapter);
Budius
  • 37,587
  • 15
  • 92
  • 134
  • Looks perfect thanks, I hadn't thought about adjusting the adapter rather than the view.. obvious now. Great little lib btw. – CodeChimp Apr 29 '15 at 13:08
  • @CodeChimp Just make sure to test it nicely because it's a very new library and might be rough around the edges. (and if you find bugs please report them) – Budius Apr 29 '15 at 13:25
  • I'll probably just be taking the relevant bits and incorporating in my own customer adapter for this immediate issue but will feedback if I find anything. – CodeChimp Apr 29 '15 at 13:28
1

The easiest way to add a footer is to set a custom adapter that has a usesFooter() flag and add 1 to the number of rows if it is true (or always add one if it doesn't need to be added by anything else). Then in onCreateViewHolder() check to see if the position is the last in the list and inflate an empty view with a height of the padding that you want to add (say 80dp)

You should also add a return if at this position in onBindViewHolder() as it is an empty view and shouldn't need its data updated.

Marcus Hooper
  • 628
  • 6
  • 12
-1

use it

  android:layout_marginBottom = "80dp"
Android Android
  • 680
  • 1
  • 7
  • 19
  • That would just place the whole view 80dp above the bottom of the activity. I want the padding at the bottom of the last item as per Gmail. – CodeChimp Apr 29 '15 at 12:47
  • a, understand now. So you should make your custom Scrollview like this http://stackoverflow.com/questions/10316743/detect-end-of-scrollview . and listen to scroll for the end and then show with animation your FAB – Android Android Apr 29 '15 at 12:52