title: How can I draw a Rectangle in Android, of a given size, that positions itself in the view to which it is added?
body: <p>I understand how to draw I shape, I am extending the <code>View</code> class, and overriding the <code>onDraw</code>, where I create a new <code>ShapeDrawbale</code> (Rectangle), which I then draw to the canvas:</p>
  
  <pre><code>    Rect rect = new Rect(x, y, x + width, y + height);
      shapeDrawable.setBounds(rect);
      shapeDrawable.getPaint().set(paint);
      shapeDrawable.draw(canvas);
  </code></pre>
  
  <p>I then want to add this to a view defined in my Activities layout xml.
  I do this by getting a handle on the view and calling:</p>
  
  <pre><code>innerLinear.addView(rectView); // where rectView is my custom class that extends View
  </code></pre>
  
  <p>My problem is that when creating the Rectangle, you have to provide <code>X</code> and <code>Y</code> coordinates.</p>
  
  <p>So - how do I get the rectanlge positioned correctly within the <code>innerLayout</code>?</p>
  
  <p>Do I have use the bounds of <code>innerLayout</code> to create the rectangle?  If so, when I call <code>innerLayout.getLeft()</code>, or <code>innerLayout.getTop()</code> etc.. 0 is always returned (I presume layout has not yet fully completed), so how do I do this?</p>
  
  <p>Is there another way?
  I feel like I'm missing something pretty basic here.</p>
  
  <p>Any help would be greatly appreciated,</p>
  
  <p>thanks</p>