Take a look at the setSpanSizeLookup method of the GridLayoutManager . It allows you to specify the range size for specific positions of your RecyclerView . Therefore, perhaps you can use it to suit your requirements for the column number of the variable.
Edit:
GridLayoutManager manager = new GridLayoutManager(context, 2); // MAX NUMBER OF SPACES manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (position == 1 || position == 6) { return 2; // ITEMS AT POSITION 1 AND 6 OCCUPY 2 SPACES } else { return 1; // OTHER ITEMS OCCUPY ONLY A SINGLE SPACE } } });
When using such a manager layout, your RecyclerView should look like this:
+---+---+ | 0 | | +---+---+ | 1 | +---+---+ | 2 | 3 | +---+---+ | 4 | 5 | +---+---+ | 6 | +---+---+
(only fields with numbers represent elements of your RecyclerView , other fields are just empty spaces)
source share