2

I am using recyclerview with staggeredGridLayoutManager. What i am trying to do is to show one header item in first row. then i want to show 2 items in each below row. But i am unable to do so.

Here is code that i used.

    recyclerView = (RecyclerView)findViewById(R.id.recycler);
    staggeredGridLayoutManager = new StaggeredGridLayoutManager(1,1);
    recyclerView.setLayoutManager(staggeredGridLayoutManager);

And these are the results

enter image description here

enter image description here

Help me with this. thanks

Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74
  • Refer this link. May help you... http://stackoverflow.com/questions/26530685/is-there-an-addheaderview-equivalent-for-recyclerview – ajantha May 05 '16 at 04:39

1 Answers1

11

You could use GridLayoutManager.

GridLayoutManager manager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false);

manager.setSpanSizeLookup(
    new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
             // 2 column size for first row
             return (position == 0 ? 2 : 1);
        }
    });

Here we are creating a GridLayoutManager with 2 grid columns. Then only for the first row, we are setting the span size to 2.

Bob
  • 13,447
  • 7
  • 35
  • 45