Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview scrolling past FAB

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" />
like image 314
CodeChimp Avatar asked Apr 29 '15 12:04

CodeChimp


2 Answers

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);
like image 52
Budius Avatar answered Nov 17 '22 17:11

Budius


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.

like image 41
Marcus Hooper Avatar answered Nov 17 '22 19:11

Marcus Hooper