Reputation: 351
I will draw 4 squares in a canvas from 16px of distance of the screen corners. I´m trying with this code:
canvas.drawRect(getWidth() - 91,getHeight() - 91, 75, 75, paint);
With this code, the square never appears. How can i draw the 4 squares?
Upvotes: 0
Views: 92
Reputation: 17140
Here is some code I did pretty fast that ought to help you out & you should be able to optimize
int squareSize = 30;
int offset = 16;
// top left
canvas.drawRect(offset, offset, offset+squareSize, offset+squareSize, paint);
// top right
canvas.drawRect(getWidth() - offset - squareSize, offset, getWidth() - offset , offset+squareSize, paint);
// bottom left
canvas.drawRect(offset, getHeight() - offset - squareSize, offset+squareSize, getHeight() - offset, paint);
// bottom right
canvas.drawRect(getWidth() - offset - squareSize, getHeight() - offset - squareSize, getWidth() - offset , getHeight() - offset, paint);
Upvotes: 1
Reputation: 2038
Should be getWidth() - 75, getHeight() - 75
.
Notice in the javadoc you have to give top left, bottom, right.http://developer.android.com/reference/android/graphics/Canvas.html#drawRect(float, float, float, float, android.graphics.Paint)
Upvotes: 0