2

I have a RecyclerView. I would like to achieve following (each circle is one RecyclerView item):

enter image description here

Each circle might have differing size.

I tried to use GridLayoutManager but it turns out that I need to provide a spanCount which is something does not fit my case.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26

1 Answers1

1

For the RecycleView layouts in a grid form with different cell spans can be achieved by using the GridLayoutManager. You will find many tutorials in the internet about how to implement it.

GridLayoutManager  layoutManager = new GridLayoutManager(this, 6);

layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        // Use whatever logic you need here to decide how 
        //  many columns to span for any given row position
        if (position % 2)
            return 3;
        else
            return 6;
    }
});

Then in onBindViewHolder update the LayoutParams.width of each view as you may require.

PerracoLabs
  • 16,449
  • 15
  • 74
  • 127