1

How can we made LinearLayout manager like this:

enter image description here

I also have checked Linear and Grid managers but it seems that in this case we need something new.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
D7ILeucoH
  • 97
  • 9

1 Answers1

1

I found the same problem in this topic and just make it fit my question:

RecyclerView LayoutManager different span counts on different rows

We just create GridLayoutManager and override method, then simplity set it in Recycler:

val layoutManager = GridLayoutManager(context, 2)
layoutManager.spanSizeLookup = object : SpanSizeLookup() {
    override fun getSpanSize(position: Int): Int {
        // 5 is the sum of items in one repeated section
        when (position % 3) {
            0 -> return 2
            1, 2 -> return 1
        }
        throw IllegalStateException("internal error")
    }
}

recycler.layoutManager = layoutManager
D7ILeucoH
  • 97
  • 9