Brian
Brian

Reputation: 2261

What is causing my Android EditText to disappear

I've been trying to create what I think is a relatively simple layout for the past hour.

What I want is to have an edit text take up the vertical real estate left over after my buttons and labels are put onto the screen. I've found plenty of information on how to do that here at SO and I feel like I've implemented that information here (layout_weight and 0dip height), however as soon as I put in the 0dip height my edittext is just not displayed.

What am I missing here?

Edit: Turns out that my Layout2 was set to match_parent and this leaves 0 available space for the weighted children to occupy. I changed the behavior there to wrap_content and all worked great.

I'm targeting Android 2.3.3

Here's my layout xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/description"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:inputType="textMultiLine"
        android:layout_weight="1" >

        <requestFocus />
    </EditText>

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/save" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/clear" />

    </LinearLayout>


</LinearLayout>

Upvotes: 1

Views: 2036

Answers (1)

lulumeya
lulumeya

Reputation: 1628

because linearLayout2 fills out the parent. linearLayout2 must have layout_weight behaviour or own height not match_parent.

Upvotes: 1

Related Questions