I would like to draw small rectangles on a Canvas. The problem is that the rectangles don´t get any border, so the result is just a big rectangle (containing all the small rectangles (20x20 rectangles as stated below)).
In my custom View
, I override onDraw:
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawRect(getWidth(), getHeight(), 50, 50, paint);
paint.setColor(Color.LTGRAY);
paint.setStrokeWidth(3);
for(int i = 0; i < 20; i++) {
for(int j = 0; j < 20; j++) {
canvas.drawRect(20*j, 20*i, 50, 50, paint);
}
}
}
For Java Swing, you can just do
g.setColor(Color.red);
for(int x = 0; x < 20; x++) {
for(int y = 0; y < 20; y++) {
g.drawRect(20 * x, 20 * y, 20, 20);
}
}
to paint the rectangles and each rectangle will have red borders.
How can I achieve this on Android?