title: Understanding how actually drawRect or drawing coordinates work in Android
body: <p>I am trying to draw a rectangle over a canvas and I am facing troubles to understand the in-depth of rectangle draw of Android. I've read tutorials and every possible but I am stuck.</p>
  
  <p>Here in the image , the red rectangle is my target.
  <img src="https://i.stack.imgur.com/GDrf7.png" alt="enter image description here"></p>
  
  <p>Irrespective of any rectangle size I need to draw the red rectangle bit above the base and in the middle of the rectangle. The worst nightmare I am facing here is understanding the X,Y Width and Height coordinates.</p>
  
  <p>Can anyone explain how that math works, sometime we go up , Y reaches to very small but same width coordinates are higher. And I am never able to justify red inner rectangle properly.In some screen it works well in some other it fails. The red rectangle sometimes come out of the parent rectangle.</p>
  
  <p><strong>Agenda is to understand how coordinates work and ensure the integrity of inner red rectangle</strong></p>
  
  <p>It'll be great to get an explanation based on an example. I am using-</p>
  
  <pre><code>void drawRect(float left, float top, float right, float bottom, Paint paint)
  </code></pre>
  
  <p>to drawing the rectangle </p>