Reputation: 4395
I want to use a gridlayout manager, the items to be in 2 columns.
I want each row to be evenly split among the items and have some small space around the items too.
I did:
val manager = GridLayoutManager(this, 4)
manager.spanSizeLookup = object: GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int = 2
}
recycler.layoutManager = manager
but even though the items in each row are of equal size, they have a huge gap between them and have no space with items bellow.
How can I fix this?
Please note that I used a specific width/size for the inflated items in the view. I guess that is an issue but not sure what should I use for those
Upvotes: 1
Views: 1547
Reputation: 13289
spanSizeLookup
property, just set the layoutManager
and add an ItemDecoration
for spacing:val manager = GridLayoutManager(this, 2)
recycler.layoutManager = manager
recycler.addItemDecoration(DividerItemDecoration(this, manager.orientation)
layout_width
set to match_parent
Upvotes: 1