Moses Aprico
Moses Aprico

Reputation: 2121

Make a "multiline" recyclerview

So, normally, a RecyclerView is either horizontal or vertical like below diagram:

enter image description here

I have no problem producing both of above. But now, I want to make a RecyclerView which is "multi-line"-ey (I don't know if this is a correct way to name it). Basically, like in notepad, if you check "Wrap Text", then the off-screen texts will be sent to the next line.

So the behavior is like HorizontalRecyclerView but the items will fill horizontally first before going below.

Assuming each size of the child items is identical, it'll be a good thing too to make it centered on the screen.

Similar like:

enter image description here

But not like (It's not centered on the screen):

enter image description here

Btw, I somehow prefer my collections to be managed by RecyclerView rather than TableLayout, since I never used TableLayout before, and RecyclerView seems the most efficient to reuse a layout of a collections.

Upvotes: 4

Views: 8081

Answers (2)

Shaishav Jogani
Shaishav Jogani

Reputation: 2121

There are 3 possible ways by which you can arrange your RecyclerView layout.

  • LinearLayoutManger – for traditional lists Look here
  • GridLayoutManager – for table view Look here
  • StaggeredGridLayoutManager - staggered grid formation Look here

[LinearLayout Image]

[Grid Layout Image]

[Staggered Grid Image]

For your question, you can use GridLayoutManager as @Ravi answered

mRecycler.setLayoutManager(new GridLayoutManager(context, numberOfColumns));

For dynamically change number of columns, you can refer this link

Upvotes: 2

Ravi
Ravi

Reputation: 35589

set GridLayoutManager for RecyclerView

mRecycler.setLayoutManager(new GridLayoutManager(context, numberOfColumns));

Reference : 1, 2

Upvotes: 7

Related Questions