This question already has answers here:
Android GridLayout with dynamic number of columns per row
(2个答案)
在11个月前关闭。
我有一个
![android - 填充所有RecyclerView区域的LayoutManager-LMLPHP android - 填充所有RecyclerView区域的LayoutManager-LMLPHP](https://dbsqp.com/x.php?x=LUoxPXE4Mj11QWhjTUNXN2lPMjhlPWJVTTh1RWc1Y3RlT0d5azFLTTk3QXZRS1pSaEsxVDI%3D)
每个圆圈的大小可能不同。
我尝试使用
然后在onBindViewHolder中,根据需要更新每个视图的LayoutParams.width。
(2个答案)
在11个月前关闭。
我有一个
RecyclerView
。我想实现以下目标(每个圆圈是一个RecyclerView
项):每个圆圈的大小可能不同。
我尝试使用
GridLayoutManager
,但事实证明我需要提供一个spanCount
,这与我的情况不符。 最佳答案
对于具有不同单元格跨度的网格形式的RecycleView布局,可以使用GridLayoutManager来实现。您将在互联网上找到许多有关如何实现它的tutorials信息。
GridLayoutManager layoutManager = new GridLayoutManager(this, 6);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
// Use whatever logic you need here to decide how
// many columns to span for any given row position
if (position % 2)
return 3;
else
return 6;
}
});
然后在onBindViewHolder中,根据需要更新每个视图的LayoutParams.width。