如何将小部件添加到具有最大行元素的网格
How to add widgets to the grid with max row of elements
我长AarrayList<Image> imageList
。当我试图将此列表中的每张图片都放入网格时,结果我只有最新的图片。
我的代码:
final int columnCount =3; //max images in the row
final int rowCount = (int) Math.ceil((double) data.size()/columnCount);
Grid grid = new Grid(rowCount, columnCount);
for (int i=0; i< imageList.size(); i++) {
for (int row = 0; row < rowCount; row++) {
for (int col = 0; col < columnCount; col++) {
grid.setWidget(row, col, imageList.get(i));
}
}
}
你能帮我解决这个问题吗
这是您的 for 循环中的逻辑错误。
你总是只是用 imageList
中的最后一张图片覆盖元素
你可以尝试这样的事情:
int row = 0;
int col = 0;
for (Image image : imageList) {
grid.setWidget(row, col, image);
col++;
if (col > 2) {
col = 0;
row++;
}
}
我长AarrayList<Image> imageList
。当我试图将此列表中的每张图片都放入网格时,结果我只有最新的图片。
我的代码:
final int columnCount =3; //max images in the row
final int rowCount = (int) Math.ceil((double) data.size()/columnCount);
Grid grid = new Grid(rowCount, columnCount);
for (int i=0; i< imageList.size(); i++) {
for (int row = 0; row < rowCount; row++) {
for (int col = 0; col < columnCount; col++) {
grid.setWidget(row, col, imageList.get(i));
}
}
}
你能帮我解决这个问题吗
这是您的 for 循环中的逻辑错误。
你总是只是用 imageList
你可以尝试这样的事情:
int row = 0;
int col = 0;
for (Image image : imageList) {
grid.setWidget(row, col, image);
col++;
if (col > 2) {
col = 0;
row++;
}
}