-1

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?

enter image description here

Siva
  • 355
  • 1
  • 6
  • 19

2 Answers2

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