Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're trying to display buttons evenly spaced across a screen, you don't need to do this in code. You can specify things like this in a layout.</p> <p>Something like this will give 6 buttons equal widths displayed horizontally.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button1" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button2" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button3" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button4" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button5" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;Button android:layout_height="wrap_content" android:id="@+id/button6" android:text="Button" android:layout_width="0dp" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>As long as you keep the layout_width to be 0dp, and set the weight to be 1, Android will automatically set the widths to be equal, no matter what number of buttons you have. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload