1
我怎样才能让recycleView
有不同尺寸的卡片? (1x1,1x2和2x1,其中1是卡长度) enter image description here不同的卡片尺寸
我怎样才能让recycleView
有不同尺寸的卡片? (1x1,1x2和2x1,其中1是卡长度) enter image description here不同的卡片尺寸
您可以使用不同跨度数的GridLayoutManager
。
这里是一些例子。
在活动:
//Initialize recyclerView and adapter before
GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter.isHeader(position)) {
//Returns span count 2 if method isHeader() returns true.
//You can use your own logic here.
return mLayoutManager.getSpanCount()
} else {
return 1;
}
}
}
});
而且这种方法添加到您的适配器类:
public boolean isHeader(int position) {
return position == 0;//you can use some other logic in here
}
您可以创建两个视图持有者。其中一人持有同一排中的两张牌,另一张持有整排一张。它肯定会看起来像你张贴的图像。为了实现多视图持有者的回收视图,请查看this。