Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems understanding Android XML layout_weight
    primarykey
    data
    text
    <p>I really tried to, but I can't understand how Android interprets <code>layout_weight</code> setting...</p> <p>What I'm trying to achieve is </p> <ul> <li>a header on top with a fixed height</li> <li>an input area at the bottom containing an EditText and a Button</li> <li>a content part in the middle that's taking all what's left of space </li> </ul> <p>When typing I'd like to grow the EditText to a specific height and to start scrolling if the text entered exceeds the available height. Doing this I need the surrounding <code>LinearLayout</code> to grow together with the EditText.</p> <p>If I define a specific height for the inner <code>LinearLayout</code> it won't grow. If I don't, the inner layout takes ALL the space instead of the ScrollView, no matter what I try using <code>layout_weight</code>. :(</p> <p>My current XML looks like that:</p> <pre><code>&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;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="I'm a header" /&gt; &lt;ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="bottom"&gt; &lt;LinearLayout android:id="@+id/itemContainer" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/ScrollView&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="50dp" android:padding="2dp" android:gravity="bottom" android:isScrollContainer="true" android:background="@drawable/steel" &gt; &lt;EditText android:id="@+id/edittext01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.2" android:scrollbars="vertical" android:fadingEdge="vertical" android:fadingEdgeLength="60dp" android:maxHeight="40dp" android:textSize="15sp" /&gt; &lt;Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.8" android:layout_gravity="right" android:text="Send" android:textStyle="bold" android:textSize="15sp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any tips are greatly appreciated!</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.
 

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