1

Is there any way to get a RecyclerView with different spanCount for every row depends on how many items can fit in a row ? Meaning when there is no more width to fit new item, it will break into a new row.

I've attached a photo so you can see what I need.

If can't be done with RecyclerView, can it be done with TableLayout ? or a listView ?

enter image description here

4

3 回答 3

1

您可以使用 Recycler View 和自定义布局管理器来执行此操作

这篇文章可能会帮助 http://wiresareobsolete.com/2014/09/building-a-recyclerview-layoutmanager-part-1/

(对不起,我没有要分享的代码。我从来没有这样做过,但我认为它可以做到这一点)

于 2016-01-27T15:40:08.723 回答
0

您也可以使用 ChipsLayoutManager。https://github.com/BelooS/ChipsLayoutManager

implementation'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'

allprojects {
repositories {
    jcenter()
}

}

于 2019-07-31T09:47:21.620 回答
0

解决方案是 FlexLayoutManager:

https://github.com/google/flexbox-layout

您需要做的就是将它添加到 Gradle 中(1.1.0 用于使用 AndroidX 工件的项目,1.0.0 其他方式):

implementation("com.google.android:flexbox:1.1.0")

并像这样创建它:

recycler.layoutManager = FlexboxLayoutManager(context, FlexDirection.ROW)
于 2019-06-06T14:22:34.487 回答