2

I'm tring to make some like RecyclerView list item image grid. It's has one main big image and some with other sizes. I've idea to use some like other holders for each image count, and choose it in adapter onCreateViewHolder method. But, I think, isn't good idea. Maybe you know some libraries or know some good practice examples?

image gallety container

1 Answers1

0

You can do this with GridLayoutManager and a custom SpanSizeLookup.

GridLayoutManager gives you the capability of saying how many columns (rows) you want a certain item to span by creating a SpanSizeLookup. The code looks like this:

    // Create a grid layout with four columns
    GridLayoutManager layoutManager = new GridLayoutManager(this, 4);

    // Create a custom SpanSizeLookup where the first item spans all four columns
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return position == 0 ? 4 : 1;
        }
    });
kris larson
  • 28,608
  • 5
  • 53
  • 67