Android recyclerview add header and bottom instance details
Android recyclerview add header and bottom instance details
If you just want to add a header, you can use this item in GitHub to add a header for the recyclerview of the linear layoutmanager, gridlayoutmanager, and staggeredgridlayoutmanager layouts. It is also very simple to use; Just place the recyclerviewheader layout on the top of the recyclerview.
Then get the recyclerviewheader object:
Assign recyclerviewheader to recyclerview
matters needing attention
RecyclerViewHeader must be called after RecyclerView has set LayoutManager.
At present, the library is applicable to recyclviews of linear layoutmanager, staggeredgridlayoutmanager and gridlayoutmanager layouts. Only vertical layout layoutmanager is supported. If you plan to use the setonscrolllistener (...) method in recyclerview, make sure to use it before the attachto (...) method of setonscrolllistener (...).
Of course, we can also write a recyclerview with a header and a bottom. The basic principle of its implementation is to add the head and bottom by returning different types through the getitemviewtype method.
First, we customize a recyclerview:
We will see that we have a recyclerwrapadapter that has not been implemented. Let's take a look at the recyclerwrapadapter, which is also the key to adding headers and tails.
We can also implement an interface to call the recyclerwrapadapter object:
In this way, we can change the RecyclerView layout into WrapRecyclerView, and then call addHeaderView or addFooterView to add the head and tail.
Thank you for reading, hope to help you, thank you for your support to this site!