Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>GridLayout</code> as suggested by someone else is not flexible enough to do this. To do this, use the <code>android:layout_weight</code> property. This allows you to fill the available space according to the fractions specified.</p> <p><strong>Example with the equal weights:</strong></p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="100dp"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="A" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="B" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="C" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><img src="https://i.imgur.com/1ITp8XY.png" /></p> <p><strong>Example with different weights:</strong></p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="100dp"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="A" /&gt; &lt;Button android:layout_weight="2" android:layout_width="match_parent" android:layout_height="match_parent" android:text="B" /&gt; &lt;Button android:layout_weight="2" android:layout_width="match_parent" android:layout_height="match_parent" android:text="C" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><img src="https://i.imgur.com/cJ5AhHp.png" /></p> <p><strong>More complex example</strong></p> <p>Here is a more complex example for a layout like used in a calculator app that uses multiple <code>LinearLayout</code>s:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="7" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="8" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="9" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="x" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="4" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="5" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="6" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="-" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="1" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="2" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="3" /&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="+" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="0" /&gt; &lt;Button android:layout_weight="1.5" android:layout_width="match_parent" android:layout_height="match_parent" android:text="." /&gt; &lt;Button android:layout_weight="1.5" android:layout_width="match_parent" android:layout_height="match_parent" android:text="=" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><img src="https://i.imgur.com/dx0q8U1.png" /></p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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