You could use layoutManager.setSpanSizeLookup
method from GridLayoutManager
Here is the way to use that
final GridLayoutManager layoutManager = new GridLayoutManager(context, 2);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (mAdapter != null) {
switch (mAdapter.getItemViewType(position)) {
case 1:
return 1;
case 0:
return 2; //number of columns of the grid
default:
return -1;
}
} else {
return -1;
}
}
});
Now you have to determine the viewType
in your adapter
@Override
public int getItemViewType(int position) {
return (position == getItemCount() - 1) ? 0 : 1; // If the item is last, `itemViewType` will be 0
}
Keep building better apps!!