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


Help me with this. thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With