我正在尝试在ImageView扩展中创建动态网格。在Android 4.0.3上它看起来很好,但是在2.2上它会在右侧和底部伸展,这样我在这些边缘的单元格看起来要大两倍。
这是网格创建代码:
cellheight = Math.round((float) (Math.floor((height - (bordersize * 2) - (linesize * (numrows - 1))) / numrows)));
cellwidth = Math.round((float) (Math.floor((width - (bordersize * 2) - (linesize * (numcols - 1))) / numcols)));
height = bordersize * 2 + (linesize * (numrows - 1)) + cellheight * numrows;
width = bordersize * 2 + (linesize * (numcols - 1)) + cellwidth * numcols;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
setImageBitmap(bitmap);
canvas.drawRect(0, 0, width, height, cellpaint);
canvas.drawRect(0, 0, bordersize, height, borderpaint);
canvas.drawRect(0, 0, width, bordersize, borderpaint);
canvas.drawRect(0, height - bordersize, width, height, borderpaint);
canvas.drawRect(width - bordersize, 0, width, height, borderpaint);
for (int i = 1; i < numrows; ++i)
canvas.drawRect(bordersize, bordersize + (i * cellheight) - (linesize / 2), width - bordersize,
bordersize + (i * cellheight) + (linesize / 2), linepaint);
for (int i = 1; i < numcols; ++i)
canvas.drawRect(bordersize + (i * cellwidth) - (linesize / 2), bordersize,
bordersize + (i * cellwidth) + (linesize / 2), height - bordersize, linepaint);
对于高度和宽度300,numrows和numcols 8,bordersize 8和linesize 3,它将高度和宽度重新计算为293并形成正方形网格。但是在2.2中,网格在右侧和底侧伸展,将边界和线条扩展到几乎与另一行/列单元格相同的大小。
我在ImageView和包装LinearLayout上都尝试过WRAP_CONTENT。我已经为setScaleType()尝试了各种值。我试过setMaxHeight()和setMaxWidth()。我没有尝试过任何东西似乎阻止了2.2的拉伸。
有什么想法吗?