'Dynamic span size in GridLayoutManager inside RecyclerView - Android Studio - Java
I'm new to android development. I have RecyclerView with GridLayoutManager. Each item inside grid is a CardView and has different width span and height span. I'm trying to change span inside onBindViewHolder but it is not working.
I want to make like this:
Each item inside RecyclerView:
public class Tile {
private String tileName, packageName;
private Drawable tileImage;
private int widthSpan, heightSpan;
Tile(String tileName, String packageName, Drawable tileImage, int widthSpan, int heightSpan) {
this.tileName = tileName;
this.packageName = packageName;
this.tileImage = tileImage;
this.widthSpan = widthSpan;
this.heightSpan = heightSpan;
}
public String getTileName() {
return tileName;
}
public void setTileName(String tileName) {
this.tileName = tileName;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public Drawable getTileImage() {
return tileImage;
}
public void setTileImage(Drawable tileImage) {
this.tileImage = tileImage;
}
public int getWidthSpan() {
return widthSpan;
}
public void setWidthSpan(int widthSpan) {
this.widthSpan = widthSpan;
}
public int getHeightSpan() {
return heightSpan;
}
public void setHeightSpan(int heightSpan) {
this.heightSpan = heightSpan;
}
}
I have tried replacing GridLayoutManager with FlexboxLayoutManager and StaggeredGridLayoutManager. But nothing is working. How can I achieve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

