I want to create a horizontal RecyclerView that displays the items in such form:
Item1 Item2 Item3 Item4 Item5 | Item11 Item12 Item13 Item14 Item15
Item6 Item7 Item8 Item9 Item10 | Item16 Item17 ...
As you can see, the items are being populated from left to right, and the default way of populating in GridLayoutManager is top to bottom.
I want to be able to set the layout manager and specify the number of columns and rows in the constructor for it do display in left-to-right manner.
The code that displays the example grid should look like this:
_binding?.horizontalRecyclerView?.layoutManager =
CustomLayoutManager(requireActivity().applicationContext, rows = 2, columns = 5, isReversed = false)
The RecyclerView should also be scrollable HORIZONTALLY.
For now, I have managed to create this RecyclerView with horizontal scroll and custom number or rows, but the numbers are being populated in the wrong order and I cannot find a way to set the number of columns. Here is my basic code:
class CustomLayoutManager(
context: Context,
rows: Int,
private val cols: Int,
isReversed: Boolean = false
) : GridLayoutManager(context, rows, HORIZONTAL, isReversed) {
override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
super.onLayoutChildren(recycler, state)
}
override fun canScrollHorizontally(): Boolean = true
override fun canScrollVertically(): Boolean = false
}
Can you help me with this?