How to set different numbers of columns per row with GridLayoutManager

970 Views Asked by At

I have virtual keyboard using RecyclerView and GridLayoutManager with default spanSize of 11 columns per row.

There are different modes for both English and Russian keyboards, but when I click to change to English keyboard view I need to have keyboard set to 9 columns per row instead of 11, as it is for Russian Keyboard.

How to set different column numbers programmatically?

1

There are 1 best solutions below

0
On BEST ANSWER

Wherever you update the keyboard layout, write this:

RecyclerView recycler =
    (RecyclerView) view.findViewById(R.id.rv_keyboard_recycler_alpha);

recycler.setLayoutManager(new GridLayoutManager([context], [num columns]);

Every time you call RecyclerView.setLayoutManager(), it will simply replace the old layout manager. You can easily swap between 11 columns and 9 columns just by setting a new layout manager.