发布于 2019-10-19 19:19:30
您可以使用flexboxlayout布局管理器,这将安排图像与大小调整顺序的网格
val layoutManager = FlexboxLayoutManager(activity)
layoutManager.flexDirection = FlexDirection.ROW
layoutManager.justifyContent = JustifyContent.FLEX_START
layoutManager.flexWrap = FlexWrap.WRAP
industryChannelBinding.manageChannelRecyclerview.setLayoutManager(layoutManager)
您必须添加flexbox依赖项
implementation 'com.google.android:flexbox:1.0.0'
发布于 2019-10-19 19:32:16
如果您使用的是Recyclerview,则可以在布局XML文件中或在设置视图时在Java代码中设置Recyclerview的layoutManager。为了在你上传的图片中获得类似的东西,我建议在你的回收站项目的布局中使用CardView。
要在XML中设置它,可以这样做
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="3"/>
其中spanCount
是所需的列数。
要在代码中做同样的事情,您可以这样做
RecyclerView recyclerView = findViewById(R.id.recyclerview)
GridLayoutManager manager = new GridLayoutManager(context, 3)
recyclerView.setLayoutManager(manager)
https://stackoverflow.com/questions/58462984
复制相似问题