Android – How to rotate Rect Object?

Rotating a rectangle this way will not get you anything usable for drawing. A Rect and a RectF do not store any information about rotation. When you use Matrix.mapRect(), the output RectF is just a new non-rotated rect whose edges touch the corner points of the rotated rectangle that you are wanting.

You need to rotate the whole canvas to draw the rectangle. Then immediately unrotate the canvas to continue drawing, so there is no issue with rotating the canvas that has other objects in it.

canvas.save();
canvas.rotate(45);
canvas.drawRect(r,paint);
canvas.restore();