Maybe this question has been asked before, but I could not seem to find a precise answer or solution. I started using the RecyclerView, and I implemented it using the LinearLayoutManager. Now I want to add custom header and footer items, that differ from the rest of the items in my RecyclerView. The header and footer should not be sticky, I want them to scroll with the rest of the items. Can somebody point out some example how to do this or just share ideas. I will appreciate it very much. Thx
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
One other way would be wrapping header and reyclerview in a coordinatorlayout:
I would suggest not to customize rv adapater.
Keep it as it as...in your rv item layout just add the footer with the layout and set the visisbilty gone.
Then when you reach the last item in adapter...make it visible.
and when you try this make sure you add this to your rv adapter.
Do the same for Header. Here i==0 // first item of list
Easiest solution to me.
You can use the library SectionedRecyclerViewAdapter, it has the concept of "Sections", where which Section has a Header, Footer and Content (list of items). In your case you might only need one Section but you can have many:
1) Create a custom Section class:
2) Create a custom ViewHolder for the items:
3) Set up your ReclyclerView with the SectionedRecyclerViewAdapter
You can use this GitHub] library to add a Header or Footer to your
RecyclerView
in the simplest way possible.You need to add the HFRecyclerView library in your project or you can also grab it from Gradle:
This is a result in image:
in your adapter add this class:
then Override the following method like this:
Now in the onCreateViewHolder method inflate your layout based on the view type::
Hope this can help.
This is very easy with ItemDecorations and without modifying any other code:
Reserve some space for drawing, inflate the layout you want drawn and draw it in the reserved space.
The code for the Decoration: