 <p>First, you are right, you get value of 0, because the screen didn't draw yet when you try to get the button <code>width</code>.</p> <p>As I see it, the only possibility to do it like you want, is to give them pre defind value in the XML file.</p> <p>For example:</p> <pre><code> &lt;Button android:id="@+id/b1" android:layout_width="25dip" android:layout_height="25dip" android:gravity="center" /&gt; </code></pre> <p>Set the width and height programmally: </p> <pre><code>DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); btnWidth = metrics.heightPixels/3 - 50;//gap btnHeight = btnWidth; Button b1 = (Button) findViewById(R.id.b1); b1.setHeight(btnWidth); b1.setWidth(btnWidth); </code></pre>