1

Good Morning-

I have a requirement in my project where I need to show the alternate rows using GridLayout manager. i.e; In First row I need to show 2 images and in Second row I need to show 3 Images.

I am using GridLayout manger with recyclerview and below is my code.

GridLayoutManager mNewlyAddedManager = new GridLayoutManager(mContext,**3**);
mMyTrawelLogsRecycleView.setLayoutManager(mNewlyAddedManager);
MyTrawellogsDetailsAdapter mImageAdapter = newMyTrawellogsDetailsAdapter(mContext, listAddedTour, false);
mMyTrawelLogsRecycleView.addItemDecoration(new SpacesItemDecoration(1));
mMyTrawelLogsRecycleView.setAdapter(mImageAdapter);

Requirement screenshot:

enter image description here

My Output image:

enter image description here

1 Answers1

0

Use 6 columns and then override getSpanSize

@Override
public int getSpanSize(int position) {
    return getSizeForItem(position);
}

You will need to make a function the returns the number of columns each item will take up, either 2 or 3.