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" />
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With