Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <a href="http://developer.android.com/reference/android/R.attr.html#weightSum" rel="nofollow">weightSum</a> and <a href="http://developer.android.com/reference/android/R.attr.html#layout_weight" rel="nofollow">layout_weight</a> attributes to control how much of the parent's available space a child view will take up. To use these, a parent layout, for example, your LinearLayout, gets the <code>android:weightSum</code> attribute. Each child layout gets the <code>android:layout_weight</code> attribute, where the sum of all child weights is the weightSum of the parent. In addition, each child should have their <code>layout_height</code> or <code>layout_width</code> set to <code>0dp</code>, whichever is going to be decided by the weight.</p> <p>Here's an example based on your diagram. Let's say you want the two top views to take up 1/4 of the screen each, and the <code>ListView</code> to take up the bottom half. Add <code>android:weightSum="4"</code> to your <code>LinearLayout</code>, <code>android:layout_weight="1"</code> to the two child layouts that you represent with <code>...Other Layouts...</code>, and <code>android:layout_weight="2"</code> to the <code>ListView</code>. Code might look something like this:</p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="4"&gt; &lt;ImageView android:layout_weight="1" android:layout_height="0dp" ...some other attributes.../&gt; &lt;LinearLayout android:layout_weight="1" android:layout_height="0dp" android:orientation="horizontal" ...some other attributes...&gt; ...some children of the LinearLayout... &lt;/LinearLayout&gt; &lt;ListView android:id="@+id/listArea" android:layout_width="match_parent" android:layout_height="0dp" android:paddingLeft="@dimen/list_padding" android:paddingRight="@dimen/list_padding" android:layout_weight="2"/&gt; &lt;/LinearLayout&gt; </code></pre>
 

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