title: Change height of android button through code
body: <p>I am trying to change the height and width of a button through code at runtime.</p>
  
  <p><strong>My layout xml</strong></p>
  
  <pre><code>   &lt;Button
      android:id="@+id/button1"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:layout_alignParentRight="true"
      android:layout_below="@+id/button2"
      android:background="@drawable/button1_background" 
      /&gt;
  </code></pre>
  
  <p><strong>Main activity code</strong></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     //some other code
     int displaywidth= getResources().getDisplayMetrics().widthPixels;
      Button f_button = (Button) findViewById(R.id.button1);
      Log.d("F_button width before is",""+ f_button.getWidth());
      f_button.setWidth(displaywidth/2);
      Log.d("F_button width after is",""+ f_button.getWidth());
  //some other code
  }
  </code></pre>
  
  <p>The Logcat shows both F_button after and before width as "0".</p>
  
  <p>what am I doing wrong.</p>
  
  <p>thanks!.</p>