3

I just want to implement sections in Staggered GridView. such as Today, Yesterday and Other. I have tried with below libraries but I have no luck.

  1. Staggered GridView
  2. RecyclerView with StaggeredGridLayoutManager.

Can you give any suggestion on how to implement this ?

Ramesh Akula
  • 5,720
  • 4
  • 43
  • 67
Sindhu
  • 33
  • 3

4 Answers4

1

You can use StaggeredGridLayoutManager with a custom ItemDecoration.

Here's a library that does that with LinearLayoutManager, sticky-headers-recyclerview. You might be able to tweak it for your needs or at least have an idea of how to do it.

paprikanotfound
  • 343
  • 3
  • 8
0

I have implemented this by using 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 have created a demo for this StaggeredGridViewSections

Ramesh Akula
  • 5,720
  • 4
  • 43
  • 67
0

If you don't need RecycleView, that is another option: https://github.com/sarahlensing/StaggeredGridView

KimKha
  • 4,370
  • 1
  • 37
  • 45
0

You can use StaggeredGridLayoutManager with one adapter and set two ItemViewTypes and for the section view set full span to true.

StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
        layoutParams.setFullSpan(true);
atabouraya
  • 3,233
  • 1
  • 26
  • 31