排列 listView 或 recyclerView 项目,如 chipGroup

Arrange listView or recyclerView items like chipGroup

我有一些标签(字符串数组),当我使用 recyclerView 或 listView 时,它只接受垂直、水平或网格排列,但我需要像芯片组惰性排列一样实现它,我该怎么做,

像这样 chipGroup

谢谢

我推荐Google's flexbox-layout library for this. It provides a FlexboxLayoutManager for use with RecyclerView:

val layoutManager = FlexboxLayoutManager(context).apply {
    setFlexDirection(FlexDirection.ROW)
}

context.findViewById<RecyclerView>(R.id.recyclerview).setLayoutManager(layoutManager)