I'm typically against posting a question without code, but I have no code to show. I'm finally converting my project from listviews and gridviews to recyclerView. In one class, I use a small gridview to place items pulled from a server.
The max number of items per row is 3, but the remainder needs to be on top. So if there's 5 items, top row has 2, bottom has 3. If there's 4 items, top row has 1, bottom has 3.
My google-fu is failing me and I'm not able to find any examples with this type of customization. If somebody could point me in the right direction, I'll post my completed code for those who find this post in the future.
Thanks all
There is a constructor of GridLayoutManager, that takes four parameters.
new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, true)
the second one is the spanCount, the number of columns or rows in the grid, while the forth is called reverseLayout and when set to true, the cells are laid out from the end to the start .
Latest update
<androidx.recyclerview.widget.RecyclerView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/daysGuideline"
app:spanCount="3" />
You can use spanCount as above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With