androidxmllayoutbuttonbar

Multiple lines in a android linear layout


I'm fiddling around with writing android apps and what I'm currently trying to do is to have a text box with a send button at the top of the page and a black button bar at the bottom.

I understand from this question that the correct way to do this would be to write something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_height="wrap_content"
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:hint="@string/edit_message" 
        android:layout_gravity="top|center"/>

     <Button
        android:layout_width="wrap_content"
        android:text="@string/button_send" 
        android:onClick="sendMessage"/>
     </LinearLayout>

     <LinearLayout android:id="@+id/footer"
         android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        style="@android:style/ButtonBar">

    <Button android:id="@+id/saveButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/menu_done" />

    <Button android:id="@+id/cancelButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/menu_cancel" />
</LinearLayout>
</LinearLayout>

but the black bar and the text box just end up on top of each other :(


Solution

  • I'm not sure if these are cut-and-past errors, but I noticed a few things in the xml. The first nested linear layout is missing a '>' before the EditText and doesn't specify a layout_height. And the first button also doesn't have a layout_height.