title: How canvas.drawRect draws a rectangle
body: <p>I have to create a custom view where I have to draw a rectangle. I'm trying to use the <code>canvas.drawRect</code> method. I wanted to create rectangles somethig like this  <a href="https://i.stack.imgur.com/d6K1z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/d6K1z.png" alt="enter image description here"></a></p>
  
  <p>the gray colored one is my custom view which is extending the <code>View</code> class.
  Inside the <code>onDraw</code> method I'm trying to draw the rectangle. </p>
  
  <p>But actually I'm confused with the parameters of the <code>drawRect</code> method.</p>
  
  <p>As per the documentation </p>
  
  <pre><code>/**
   * Draw the specified Rect using the specified paint. The rectangle will
   * be filled or framed based on the Style in the paint.
   *
   * @param left   The left side of the rectangle to be drawn
   * @param top    The top side of the rectangle to be drawn
   * @param right  The right side of the rectangle to be drawn
   * @param bottom The bottom side of the rectangle to be drawn
   * @param paint  The paint used to draw the rect
   */
  </code></pre>
  
  <p>What I assume is that left and top forms the x,y coordinates of the starting point, and right is the width and bottom is the height. But it doesn't seem to work that way.</p>
  
  <p>I tried something like this to draw one rectangle but it does not draw anything     </p>
  
  <pre><code>       paint.setColor(Color.BLUE);
         canvas.drawRect(5, canvas.getHeight()/2, 30, 30, paint );
  </code></pre>
  
  <p>Can anyone please tell how exactly a rectangle is drawn using these values? </p>
  
  <p>It would be very helpful if someone could show the code to draw at least the first rectangle. </p>
  
  <p>My requirement is like, the number of inner rectangles are dynamic, so if I pass some 4 to this View, it should create 4 equal width rectangles horizontally.  something like  <a href="https://i.stack.imgur.com/kksuH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kksuH.png" alt="enter image description here"></a></p>
  
  <p>Thanks in advance!!</p>