I want to use an expandable recyclerview with grid layout manager, but with specific expanding behaviour which expand to the full width of the screen.
Is there any way or maybe libraries to achieve this? Thank you.
I want to use an expandable recyclerview with grid layout manager, but with specific expanding behaviour which expand to the full width of the screen.
Is there any way or maybe libraries to achieve this? Thank you.
I don“t know if Christopher's link allows for the expandable to occupy the whole 2 grids. There might be a way using a combination of getItemViewType(), and setSpanSizeLookup().
@Override
public int getItemViewType(int position) {
if (position == positionOfClickedItem + 2){
return TYPE_EXPANDABLE;
} else {
return TYPE_CAR_ITEM;
}
}
Bind the data according to its position, and carry the position to your activity to set SpanSizeLookup. You would then have to notify the adapter of a change:
// Create a SpanSizeLookup which returns 2 grids span if its the expandable or 1 otherwise.
gridLayout.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == positionOfClickedItem) {
return 2;
} else {
return 1;
}
}
});
I think the transformation answer works better but just in case the Span size is important.