Daniel Ruiz
Daniel Ruiz

Reputation: 351

Paint 4 rectangles 16px from the 4 corners

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

Answers (2)

petey
petey

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

eduyayo
eduyayo

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

Related Questions