How do I implement a Staggered GridView with sections?
I just want to implement sections in a Shaggered GridView. , for example Today, Yesterday and Other. I tried with below library but I had no luck.
- Spaced GridView
- RecyclerView with StaggeredGridLayoutManager.
Can you give any suggestion on how to implement this?
I have implemented this using a RecyclerView with StaggeredGridLayoutManger in SimpleAdapter.java .
if (position % 5 == 0) {
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);
} else {
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
layoutParams.setFullSpan(false);
}
Here is the link I created for this StaggeredGridViewSections
You can use StaggeredGridLayoutManager with custom ItemDecoration.
Here's a library that does it with LinearLayoutManager, sticky-headers-recyclerview . You may be able to customize it to your needs, or at least have an idea of how to do it.
If you don't need RecycleView, this is another option: https://github.com/sarahlensing/StaggeredGridView
You can use the StaggeredGridLayoutManager with one adapter and set two ItemViewTypes and set the full range to true for the section slice.
StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
layoutParams.setFullSpan(true);