我试图绘制一个生命游戏应用程序的矩形对象的网格。在这个阶段,我只是想让基础网格工作。最终,它将评估一个布尔数组的实况和死亡单元格,并相应地更改绘制样式。为了测试目的,我尽可能简化了代码。我试图绘制一个没有填充的100x100矩形的9x6网格。试图在Android中使用drawRect绘制栅格获取奇怪的输出
这里是我的代码:
paintGrid.setStyle(Paint.Style.STROKE); //sets paint style for grid squares
int gm = 100; //gridMultiplier determines rectangle size in this case 100x100
for(int r = 0; r < 9; r++) //paints grid with 9 rows
{
for(int c = 0; c < grid[0].length; c++) //6 columns
{
top = r*gm; //sets LEFT side
bottom = top+gm; //sets RIGHT side
left = c*gm;
right = left+gm;
Log.v(LOGTAG, "left: " + left + " right: "+ right+ " top: " + top +
" bottom: " + bottom); //testing
canvas.drawRect(left, top, bottom, right, paintGrid); //paints dead Cell
}
}
我希望这首先绘制上排左到右,然后在第二行画一个网格,并继续,直到完成。 Instead I get this for an output.
用于测试的logcat输出im似乎表明循环工作正常。我得到: Left:0 right 100 top 0 bottom 100 Left:100 right 200 top 0 bottom 100 Left:200 right 300 top 0 bottom 100 Left:300 right 400 top 0 bottom 100 Left:400 right 500 top 0底部100
左向右0 100 100强底部200 左向右100 200 100强底部200 左向右200 300 100强底部200 ...等
林在我无计可施到此为止!我的印象是二维数组很重要,所以我一直试图保持这种设置。有什么建议么?提前致谢!
谢谢!我并不感到奇怪,这是一件愚蠢的事情。 – agarfin 2014-12-05 21:18:50