我需要弄清楚如何画垂直和水平线通过一个细胞的中心。
顺便说一句,我有一个有100x100个细胞的2D网格,如何在这些细胞内部画出一条线,将每个细胞分成4部分?
我用咆哮画:
//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);
}
}这画了一些相似的东西(每个单元格都有一个GestureDetector)

找不到一种方法来画其他的线,这一次通过在每个细胞内,使它分裂成四个部分。
像这样的东西(红色是细胞):

发布于 2018-06-05 16:52:43
//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);
}
}作为附带说明,我会考虑使用函数而不是重复代码!祝你好运;)
https://stackoverflow.com/questions/50705175
复制相似问题