Reputation: 278
Aoa i want to get Recyclerview show like this :
I used below GridLayoutManager code But i get output like this
GridLayoutManager manager = new GridLayoutManager(this, 2);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return (position % 3) > 0 ? 1 : 2;
}
});
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
UserAdapter userAdapter = new UserAdapter(this,userModelList);
rvItem.setLayoutManager(manager);
rvItem.setAdapter(userAdapter);
Please guide me either this is possible? If yes then How?
Upvotes: 0
Views: 97
Reputation: 47
I think the solution might be doing the following : Since what you are doing is sending the position that ranges from i=0 to n and you use modulo of 3 . Hence if i=0 and i>0 is false that is why the first line is 1 and the second line is i=1 and i>0 that is why you get 2 ...
@Override
public int getSpanSize(int position) {
return (position % 3) > 0 ? 2 : 1;
}
How about switching the ternary condition and trying to maybe use modulo of 2 instead 3 ? Or maybe switch the 2 and 1 ?? It seems that you are on the right path a little experimentation will do the trick :) Best of luck !!!
Upvotes: 1