title: getWidth() and getHeight() for custom view give wrong values
body: <p>I've got a Custom View where I draw a grid onto a canvas. I want the grid to be drawn so that the outer edges of the grid coincide with the edges of the device screen. I use the <code>getWidth()</code> and <code>getHeight()</code> methods to determine the dimensions of my grid and then draw it, but the grid that appears always has cells drawn off-screen. </p>
  
  <p>If I get the width and height of the display and use those for drawing instead then the width of my grid will be what I want, but the height is still off because some the height of the display is taken up by battery and wifi indicators, etc. Also, I don't want to use these values as I want to be able to embed my view in larger xml layouts.</p>
  
  <p>Below is the code where I find my view width and height in my custom view:</p>
  
  <pre><code>@Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh){
      cellWidth = w/nCols;
      cellHeight = h/nRows;
      //find view dimensions
      viewWidth = getWidth();     //this is just equal to w
      viewHeight = getHeight();   //this is just equal to h
      super.onSizeChanged(w,h,oldw,oldh);
  }
  </code></pre>
  
  <p>and the onDraw of my custom view:</p>
  
  <pre><code>@Override 
  protected void onDraw(Canvas canvas){
      super.onDraw(canvas);
  
      canvas.drawRect(0,0,viewWidth,viewHeight, background);    
  
      for(int i=0; i &lt;= nRows; i++){
          canvas.drawLine(0,i*cellHeight, nCols*cellWidth,i*cellHeight,lines);
          canvas.drawLine(i*cellWidth, 0, i*cellWidth, nRows*cellHeight, lines);
      }
  }       
  </code></pre>
  
  <p>}</p>
  
  <p>The approach I've followed is similar to <a href="http://www.syedrakib.com/2011/02/how-to-get-width-and-height-dimensions.html" rel="nofollow">this</a> but has not worked. 
  How can I get the true values for the width and height of my view?
  Thanks for reading!</p>