How can I make it so that in the recycleView
there are differents size cards? (1x1, 1x2 and 2x1 where 1 is the card length)
enter image description here
Asked
Active
Viewed 825 times
1

mhatch
- 4,441
- 6
- 36
- 62

Tibold Jozsa
- 15
- 4
2 Answers
1
You can create two view holders. One of them holds the two cards that are in the same row, the other holds the full row one. It would definitely look like the image you posted. For implementing the recycler view with multiple view holders check out this.

Community
- 1
- 1

Drilon Blakqori
- 2,796
- 2
- 17
- 25
0
You can use GridLayoutManager
with different span count.
Here is some example.
In activity:
//Initialize recyclerView and adapter before
GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter.isHeader(position)) {
//Returns span count 2 if method isHeader() returns true.
//You can use your own logic here.
return mLayoutManager.getSpanCount()
} else {
return 1;
}
}
}
});
And add this method to your adapter class:
public boolean isHeader(int position) {
return position == 0;//you can use some other logic in here
}

dzikovskyy
- 5,027
- 3
- 32
- 43