Как сохранить просмотр списка от нажатия текста вниз? - PullRequest
0 голосов
/ 18 апреля 2011

С TextView сверху, с ListView вторым, с TextView снизу, как мне сохранить последний TextView закрепленным в нижней части экрана, ListView для заполнения между верхним textView и нижним TextView, и никогда не иметьсписок нажмите последний TextView от экрана?

Ответы [ 4 ]

3 голосов
/ 18 апреля 2011

Вот что я делаю. (Следуя этому примеру, вы, конечно, замените ScrollView своим ListView.)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="My Header Text" />
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all.  Lots of content that needs to be scrolled, to see it all." />
    </ScrollView>
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="My Footer Text" />
</LinearLayout>

А вот как это выглядит на моем G2.

image

1 голос
/ 18 апреля 2011

вам нужно android:layout_weight="1" в ListView и android:layout_weight="0" в нижнем TextView. Я делаю то же самое, что и ты, и это работает

Редактировать: фактически вам может понадобиться поместить вложенный LinearLayout android:layout_weight="0" вокруг нижнего TextView. У меня есть нижняя строка, которая заключена в LL, но вы можете использовать layout_weight непосредственно в вашем TextView

1 голос
/ 18 апреля 2011

Вы можете сделать это двумя способами. Во-первых,

Выньте TextView из LinearLayout, затем объедините LinearLayout и TextView внутри RelativeLayout. Добавьте android: layout_alignParentBottom = "true" в TextView.

<RelativeLayout>
    <LinearLayout>
        <!-- All your other elements in here -->
    </LinearLayout>
    <TextView
        android:layout_alignParentBottom="true" />
</RelativeLayout>

Во-вторых, перенести всю относительную компоновку вниз (как я использую)

<RelativeLayout
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    <Button
        android:text="@string/label_submit_button"
        android:id="@+id/Button"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/EditText"
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@id/Button"
        android:layout_height="wrap_content" />
</RelativeLayout>
1 голос
/ 18 апреля 2011

Гнездо линейного макета для хранения списка.

...