//Draw grid lines horizontally and vertically
for (int i = 0; i < gameBoard.length; i++) {
if((i * cellWidth) + xOffset > 0 && (i * cellWidth) + xOffset < width) {
canvas.drawLine((i * cellWidth) + xOffset, 0, (i * cellWidth) + xOffset, height, blackPaint);
}
}
for (int i = 0; i < gameBoard[0].length; i++) {
if((i * cellHeight) + yOffset > 0 && (i * cellHeight) + yOffset < height) {
canvas.drawLine(0, (i * cellHeight) + yOffset, width, (i * cellHeight) + yOffset, blackPaint);
}
}
xOffset += cellWidth * 0.5f;
yOffset += cellHeight * 0.5f;
//Draw grid lines horizontally and vertically AGAIN.. but now with offsets moved half size to the right/bottom
for (int i = 0; i < gameBoard.length; i++) {
if((i * cellWidth) + xOffset > 0 && (i * cellWidth) + xOffset < width) {
canvas.drawLine((i * cellWidth) + xOffset, 0, (i * cellWidth) + xOffset, height, blackPaint);
}
}
for (int i = 0; i < gameBoard[0].length; i++) {
if((i * cellHeight) + yOffset > 0 && (i * cellHeight) + yOffset < height) {
canvas.drawLine(0, (i * cellHeight) + yOffset, width, (i * cellHeight) + yOffset, blackPaint);
}
}
另外,我会考虑使用函数而不是重复代码!祝你好运!)