Ali Ali
Ali Ali

Reputation: 1874

How to wrap RecyclerView items horizontally and vertically at the same time?

The Items should look like this: RecyclerView items as grid

Upvotes: 0

Views: 94

Answers (2)

Dorkmania
Dorkmania

Reputation: 962

Assuming an arbitrary number of columns and rows, you could try using this library with a FlexboxLayoutManager for your RecyclerView. As you noted, you could also use a GridLayoutManager in case your columns are fixed.

Upvotes: 2

Ali Ali
Ali Ali

Reputation: 1874

It's simply can be done using GridLayoutManager insted of LinerLayoutManager and without nested RecyclerView or any additional Layout like this:

RecyclerView.LayoutManager mRecyclerGrid=new GridLayoutManager(this,3,LinearLayoutManager.VERTICAL,false);
mRecyclerView.setLayoutManager(mRecyclerGrid);

You can set how many items should appear on a row (replace the 3).

Upvotes: 0

Related Questions