StaggeredGridLayoutManager. How To Have One Item In First Row And 2 Item Other Rows
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 una
Solution 1:
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.
Post a Comment for "StaggeredGridLayoutManager. How To Have One Item In First Row And 2 Item Other Rows"