有没有办法根据Android中RecyclerView的项目文本长度为每行设置不同的'spanCount'

时间:2018-12-25 05:28:03

标签: android

实际上,我正在尝试为当前应用程序设计以下页面。

Expected Screen

如果仔细观察以上屏幕截图,您会发现每一行中的document.getElementById("formId").setAttribute("age", 22); 是不同的(有时是2/3/1),并且似乎这些项目是根据相应的{ {1}}或Span-Count。因此,考虑到这些要点,我正在尝试设计此页面。目前,我将item text-lengthItem-Width一起使用

下面是我的代码:

RecyclerView

使用上面的代码,我的屏幕如下所示-

enter image description here

您可以清楚地注意到“第一屏幕截图”(预期)和“第二屏幕截图”(“现在看”)之间的差异,第二屏幕截图显示了固定的“跨度计数”(即3)。代码),并且该项目上的文本也不是完全可见的。

1 个答案:

答案 0 :(得分:1)

您需要使用FlowLayoutManager

implementation 'com.xiaofeng.android:flowlayoutmanager:1.2.3.2'

RecyclerView

FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
flowLayoutManager.setAutoMeasureEnabled(true);
recyclerView.setLayoutManager(flowLayoutManager);