0

Why is my layout, shown below, containing EditText and Button, not shown? The MapView is taking up the entire view.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
    a:layout_width="fill_parent"
    a:layout_height="fill_parent" >

<LinearLayout
    a:layout_width="fill_parent"
    a:layout_height="wrap_content"
    a:orientation="vertical" >

    <LinearLayout
        a:layout_width="fill_parent"
        a:layout_height="wrap_content"
        a:orientation="vertical" >

        <RelativeLayout
            a:layout_width="fill_parent"
            a:layout_height="40dip"
            a:background="#50ffffff"
            a:orientation="horizontal"
            a:paddingBottom="0dip"
            a:paddingLeft="5dip"
            a:paddingRight="5dip"
            a:paddingTop="5dip" >

            <Button
                a:id="@+id/smsCancelButton"
                a:layout_width="70dip"
                a:layout_height="40dip"
                a:layout_alignParentRight="true"
                a:layout_weight="1.0"
                a:enabled="false"
                a:text="@string/sms_cancel_abbr" />
        </RelativeLayout>

        <com.google.android.maps.MapView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:apiKey="not shown"
            android:clickable="true" />
    </LinearLayout>

    <SeekBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="26dp"
        a:paddingLeft="10dip"
        a:paddingRight="10dip"
        a:paddingTop="30dip"
        android:max="100" >
    </SeekBar>
</LinearLayout>
<!-- #dcdcdc -->

<LinearLayout
    a:layout_width="fill_parent"
    a:layout_height="wrap_content"
    a:layout_alignParentBottom="true"
    a:background="#dcdcdc"
    a:orientation="horizontal"
    a:paddingBottom="5dip"
    a:paddingLeft="5dip"
    a:paddingRight="5dip"
    a:paddingTop="5dip" >

    <EditText
        a:id="@+id/smsBody"
        a:layout_width="0dip"
        a:layout_height="wrap_content"
        a:layout_weight="1.0"
        a:autoText="true"
        a:capitalize="sentences"
        a:hint="@string/sms_enter_message"
        a:imeOptions="actionSend|flagNoEnterAction"
        a:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
        a:maxLines="10"
        a:nextFocusRight="@+id/send_button" />

    <LinearLayout
        a:layout_width="wrap_content"
        a:layout_height="wrap_content"
        a:orientation="vertical" >

        <Button
            a:id="@+id/smsSendButton"
            a:layout_width="wrap_content"
            a:layout_height="wrap_content"
            a:layout_marginLeft="5dip"
            a:layout_weight="1.0"
            a:enabled="false"
            a:nextFocusLeft="@+id/smsBody"
            a:text="@string/sms_send_abbr" />
    </LinearLayout>
</LinearLayout>

2
  • 1
    You probably want to set the layout_height of the MapView to 0dp, and the layout_weight to 1. Commented Jul 20, 2012 at 23:21
  • 3
    Have you ever consider to rebuild your layout structure? There are only have 5 Views and you're making complicated a simple thing. I recommend you to build your layout with one Relative Layout. Commented Jul 20, 2012 at 23:34

1 Answer 1

1

Your topmost LinearLayout doesn't explicitly set an orientation. LinearLayout defaults to horizontal orientation if you don't specify one. So the first pane containing the map, whose width is set to fill_parent, fills the entire screen and the second pane, containing the EditText and Button, is cut off the right-hand side of the screen.

You need to be aware that setting any child inside a LinearLayout to match_parent will eat up all the space remaining, so that any children following will not show. For instance, say you have a vertical LL, and four children: a, b, c, and d. Height on a is set to wrap_content, and is only maybe 10 or 20dp high. b has height set to fill_parent, c and d both have height set to wrap_content. In this example, b will fill the entirety of the screen that isn't taken up by a, and c and d will never show. It's a frustrating limitation of LinearLayout that you can partially, but not completely, workaround using weights.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.