i use GridLayoutManager
to RecyclerView
but i require every four row this (provide image) ViewType
give me solution
Asked
Active
Viewed 69 times
-5

Philipp
- 468
- 3
- 24

user3774552
- 53
- 8
2 Answers
0
RecyclerView
supports multiple viewtypes
.
Take a look into this:
How to create RecyclerView with multiple view type?
@Override
public int getItemViewType(int position) {
//Every 5th view should be different
return position % 5;
}
@Override
public int getItemCount() {
return 2;
}

Philipp
- 468
- 3
- 24
-
i use your given answer in link but problem facing please open this link https://i.stack.imgur.com/fWddZ.jpg i want to require this type https://i.stack.imgur.com/lnW8Y.jpg – user3774552 Jul 18 '18 at 14:24
-
You need to adopt some functions. You have 2 `viewTypes` with 2 layouts, every 5th viewtype is different. edited my response – Philipp Jul 18 '18 at 14:37
0
Assumning all items have similar views Try This:
GridLayoutManager layoutManager = new GridLayoutManager(DashboardActivity.this, 2);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (positions you wish to have a different view) {
return 2;
}
return 1;
}
});

prashant17
- 1,520
- 3
- 14
- 23