Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 539
ojas Avatar asked Sep 10 '15 02:09

ojas


People also ask

What is nested recycler view?

A nested RecyclerView is an implementation of a RecyclerView within a RecyclerView. An example of such a layout can be seen in a variety of apps such as the Play store where the outer (parent) RecyclerView is of Vertical orientation whereas the inner (child) RecyclerViews are of horizontal orientations.

How does recycler view work internally?

RecyclerView does not allocate an item view for every item in your data source. Instead, it allocates only the number of item views that fit on the screen(Viewport) and it reuses those item layouts as the user scrolls.


1 Answers

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.

like image 166
Kushal Sharma Avatar answered Sep 16 '22 19:09

Kushal Sharma