I have a table to be displayed in RecyclerView. Currently i'm using GridLayoutManager with vertical orientation. Since all my logic depends on the vertical orientation of GridLayoutManager, i'm unable to shift to horizontal orientation or StaggeredLayoutManager. Is there a way to alter RecyclerView children measure so that the first cell of each row can have a different width?
Asked
Active
Viewed 227 times
-1
-
can u share the design which you are implementing – hasan_shaikh Jul 09 '18 at 11:03
-
@hasan_shaikh check out the image.. you can see i'm trying to have different width for headers – Siva Jul 09 '18 at 11:07
2 Answers
0
I suggest you to use SpanSizeLookup.
Something like this:
GridLayoutManager manager = new GridLayoutManager(context, 2);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(adapter.getItemViewType(position)) {
// first cell type
case 1:
return 1;
default:
return 2;
}
}
});
And in you adapter you should override getItemViewType
and return different types for your cells.

Vera Rivotti
- 500
- 4
- 9
0
After some source digging, i have found that method GridLayoutManager.calculateItemBorders() is responsible for item width (cachedBorder). But since change that method is private, we cannot override it.
Hope this helps anyone who is facing a similar situation.

Siva
- 355
- 1
- 6
- 19