我将开发一个应用程序,我用这种方法绘制矩形:
private int columnWidth = 1;
private int rowHeight = 1;
private int nbColumns = 1;
private int nbRows = 1;
public static final int DEFAULT_SIZE = 150;
private void initWorld() {
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point point = new Point();
display.getSize(point);
// we calculate the number of columns and rows for our World
nbColumns = point.x / DEFAULT_SIZE;
nbRows = point.y / DEFAULT_SIZE;
// we calculate the column width and row height
columnWidth = point.x / nbColumns;
rowHeight = point.y / nbRows;
world = new World(nbColumns, nbRows);
}
// Method to draw each cell of the world on the canvas
private void drawCells(Canvas canvas) {
for (int i = 0; i < nbColumns; i++) {
for (int j = 0; j < nbRows; j++) {
Cell cell = world.get(i, j);
r.set((cell.x * columnWidth) - 1, (cell.y * rowHeight) - 1,
(cell.x * columnWidth + columnWidth) - 1,
(cell.y * rowHeight + rowHeight) - 1);
// we change the color according the alive status of the cell
p.setColor(cell.alive ? DEFAULT_ALIVE_COLOR : DEFAULT_DEAD_COLOR);
canvas.drawRect(r, p);
}
}
}
谁能告诉我,我怎样才能在矩形之间得到一些空格或线条?