Несколько строк в линейном макете Android

Я возился с написанием приложений для Android, и сейчас я пытаюсь сделать текстовое поле с кнопкой отправки вверху страницы и черной панелью кнопок внизу.

Из этого вопроса я понимаю, что правильным способом было бы написать что-то вроде этого:

<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>

но черная полоса и текстовое поле просто оказываются друг над другом:(

1 ответ

Решение

Я не уверен, являются ли это ошибками, но я заметил несколько вещей в XML. В первом вложенном линейном макете отсутствует ">" перед EditText и не указывается layout_height. И первая кнопка также не имеет layout_height.

Другие вопросы по тегам