Rectangles can be drawn in a few different ways, the easiest being to specify the left y coordinate, the top x coordinate, the right y coordinate, and the bottom x coordinate along with a Paint object.
float leftx = 20;
float rightx = 50;
float bottomy = 100;
canvas.drawRect(leftx, topy, rightx, bottomy, paint);
Another means to draw a rectangle is to pass in a RectF object. RectF is a class that defines a rectangle using float values representing the left, top, right, and bottom coordinates.
Paint paint = new Paint(); float leftx = 20; float topy = 20; float rightx = 50; float bottomy = 100;
RectF rectangle = new RectF(leftx,topy,rightx,bottomy);
Was this article helpful?