I need to color list item diagonally of grid layout manager of span count 2
for example:
- color 0th, 3rd,4th,7th, 8th and so on position in One color
- color 1th, 2nd, 5th, 6th, 9th,10th and so on position in another color
Please provide any logic for this for coloring item of recyclerview
corresponding image
In this picture item next to hindi is has to color as item english is colored
CodePudding user response:
As @Pawel mentioned in the comment, you can add the following logic in your onBindViewHolder
function:
val mod = adapterPosition % 4
val backgroundColor = if(mod == 0 || mod == 3) color1 else color2
// Set this color to your view
Here color1
will be set for elements at index 0, 3, 4, 7, 8, ... and color2
will be set for the remaining positions.