It is very simple to do that.
The solution is to use the same approach of the LinearLayoutManager
with a GridLayoutManager
and then use the method setSpanSizeLookup
on the LayoutManager
like this:
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(myAdapter.getItemViewType(position)){
case MyAdapter.VIEW_TYPES.Product:
return 1;
case MyAdapter.VIEW_TYPES.Progress:
return 2; //number of columns of the grid
default:
return -1;
}
}
});
This will automatically make the item cover a full row of the grid (if the row is not totally empty this item goes to the next row).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…