OJAS JUNEJA OJAS JUNEJA - 6 days ago 9
Android Question

ANDROID: Multiple Card Views inside recycler view

Please see below image:

How can i insert multiple card View inside a Recycler View.
or any other way to achieve this.

Using of Recycler view is must.

enter image description here

Answer

I think the proper way to achieve the goal as described in the image attached would be to use GridLayoutManager rather than using a RecyclerView.LayoutManager or LinearLayoutManager.

The LayoutManager we attach on the RecyclerView decides the number of columns. There are like 3 subclasses.

  1. LinearLayoutManager
  2. GridLayoutmanger
  3. StaggeredGridLayoutmanger

In your activity where you initialize the RecyclerView.LayoutManager, change

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManger(this);

to

GridLayoutManager mLayoutManager = new GridLayoutManger(this, 2);

2 being the span count of the grid. Each item will be placed in a single span and thus you will have 2 columns in your recycler view.

Comments