RecyclerView makes a range of items in multiple rows

I have a collection of photos and I use RecyclerView to display them. I want to have the first element in my RecyclerView span 2 columns AND 2 rows: enter image description here

How can I achieve this, I know that with GridLayoutManager you can do it

  GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        if (position == 0) {
            return 2;
        } else {
            return 1;
        }
    }
});

but this only applies to columns, not rows. So, how can I achieve this layout in RecyclerView ?, Note: this layout is used on instagram and Google Photos.

this question was asked, but without the solution "Good solution"

+4
source share

Source: https://habr.com/ru/post/1690731/


All Articles