Android ListView перекрывается

Я пытаюсь иметь LinearLayout ниже ListView, который довольно длинный, поэтому ListView перекрывает макет ниже. Я пробовал несколько способов, иногда это выглядит хорошо в предварительном просмотре, но не в эмуляторе во время выполнения. Это мой простой макет (было несколько других, которые также не работали). Я злюсь из-за этой бедной проблемы. Может кто-нибудь решить мою загадку, пожалуйста?

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

<LinearLayout
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="send"
        android:text="@string/odeslat" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="reset"
        android:text="@string/reset" />
</LinearLayout>

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/footer">

    <ListView
        android:id="@+id/questionlst"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>
</RelativeLayout>

1 ответ

Решение

Вам просто нужно добавить android:layout_alignParentBottom="true" в ваш колонтитул LinearLayout, Это оно! Вы получаете что-то вроде этого:

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

<LinearLayout
    android:id="@+id/footer"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="send"
        android:text="hey" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="reset"
        android:text="hey" />
</LinearLayout>

<ListView
    android:id="@+id/questionlst"
    android:layout_above="@id/footer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Только что проверил, работает в Android Studio.

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