title: How to retrieve the dimensions of a view?
body: <p>I have a view made up of <code>TableLayout, TableRow and TextView</code>. I want it to look like a grid.  I need to get the height and width of this grid.  The methods <code>getHeight()</code> and <code>getWidth()</code> always return 0.  This happens when I format the grid dynamically and also when I use an XML version.  </p>
  
  <p>How to retrieve the dimensions for a view?  </p>
  
  <hr>
  
  <p>Here is my test program I used in Debug to check the results: </p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TableLayout;
  import android.widget.TextView;
  
  public class appwig extends Activity {  
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maindemo);  //&lt;- includes the grid called "board"
        int vh = 0;   
        int vw = 0;
  
        //Test-1 used the xml layout (which is displayed on the screen):
        TableLayout tl = (TableLayout) findViewById(R.id.board);  
        tl = (TableLayout) findViewById(R.id.board);
        vh = tl.getHeight();     //&lt;- getHeight returned 0, Why?  
        vw = tl.getWidth();     //&lt;- getWidth returned 0, Why?   
  
        //Test-2 used a simple dynamically generated view:        
        TextView tv = new TextView(this);
        tv.setHeight(20);
        tv.setWidth(20);
        vh = tv.getHeight();    //&lt;- getHeight returned 0, Why?       
        vw = tv.getWidth();    //&lt;- getWidth returned 0, Why?
  
      } //eof method
  } //eof class
  </code></pre>