Recyclerview Horizontal Span And Spacing Issues
Solution 1:
Why is the recyclerview items populated in vertical fashion?
1 4 2 5 3 6
A RecyclerView is intended for Lists that scroll. If you have a horizontal layout, it will fill the first column, followed by the second, then the third, etc. After all, that's how we would expect a list to work. And that's why the "numbering is off". It starts with the first column, going on to the next once it is filled.
When my item count is 6 , how do i avoid the space between the rows?
I don't know your setup, but I'm guessing your recyclerviews height is set to match_parent
, so it's probably just using up all the available height. wrap_content
height for the recyclerview might help.
When my items are say 4 ,i want to show my items as
1 2 3 4
or
1 3 4 2
Again, see above, that's not how a RecyclerView works. It will always fill the columns one by one, and not start with a row. 4 Items with a column count of 2 will always fill the first columns first, like below.
1 3
2 4
A RecyclerView might not fit all your needs. You could switch to a vertical grid layout with 3 columns with less than 9 items. That way it would not scroll horizontally, and it would even fill the views up like you described. For more than 9 items you'd still show the horizontal version and have it scroll.
What you're actually describing is a custom layout: You want a view that behaves in a specific fashion. You could have a look on how to create your own ViewGroup
and use that to lay out all the views however you like. Unless you want to show long lists, that might be a good alternative option.
Post a Comment for "Recyclerview Horizontal Span And Spacing Issues"