I'm tring to make some like RecyclerView list item image grid. It's has one main big image and some with other sizes. I've idea to use some like other holders for each image count, and choose it in adapter onCreateViewHolder method. But, I think, isn't good idea. Maybe you know some libraries or know some good practice examples?
答案 0 :(得分:0)
您可以使用GridLayoutManager
和自定义SpanSizeLookup
执行此操作。
GridLayoutManager
使您能够通过创建SpanSizeLookup
来说明您希望特定项目跨越多少列(行)。代码如下所示:
// Create a grid layout with four columns
GridLayoutManager layoutManager = new GridLayoutManager(this, 4);
// Create a custom SpanSizeLookup where the first item spans all four columns
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return position == 0 ? 4 : 1;
}
});