Any idea about how to correct apply GridLayoutManager
leopku opened this issue · 3 comments
Is your feature request related to a problem?
Thanks for your many useful projects.
I wanna apply GridLayoutManager like below:
section1
item1 item2 item3
item4 item5 item6
section2
item21 item22 item23
item24 item25 item26
If using GridLayoutMananger directly, result would like below:
section1 item1 item2
item3 section2 item21
item22 item23
Any idea about it?
A clear and concise description of what the problem is.
Describe the solution you'd like:
A clear and concise description of what you want to happen.
Describe alternatives you've considered:
A clear description of any alternative solutions you've considered.
Hi, @leopku
In that case, you should use the RecyclerView
with LinearLayour
, and add a second RecyclerView
with GridLayoutManager
in the item layout. (not section's header layout).
Here is some examples using SampleAdapter and SampleViewHolder.
override fun layout(sectionRow: SectionRow): Int {
when (sectionRow.row) {
0 -> return R.layout.item_sample1_header
else -> return R.layout.item_sample
}
}
The R.layout.item_sample
shoud be like below.
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
Make a new adapter and viewholder for the grid item. (ItemDetailAdapter, ItemDetailViewHolder).
After that, here is an example of the SampleViewHolder.
itemView.run {
recyclerView.adapter = ItemDetailAdapter()
recyclerView.layoutManager = GridLayoutManager(context(), 3)
// add items
}
Thank you for your issue :)