0

У меня есть Activity с ListView и с кнопками в самом низу. Как мне сделать так, чтобы прокручивался только ListView, а не весь Activity, и чтобы не пропадали кнопки внизу экрана.

Код Activity:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/activity_main_listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/activity_main_start"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Start" />

            <Button
                android:id="@+id/activity_main_stop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Stop" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/activity_main_clear"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Clean" />

            <Button
                android:id="@+id/activity_main_refresh"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Refresh" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Обновление

Если я помещаю кнопки вверху экрана, то список не получается, всё так, как мне надо. (Список прокручивается, но экран вместе с ним не прокручивается и кнопки находятся вверху). А мне надо, чтобы было так же, но кнопки были внизу.

2
  • @BORSHEVIK, сделайте главный слой - RelativeLayout: слой с кнопками привяжите как layout_alignParentBottom, у Listview уберите внешний слой (он не нужен) и сделайте ему layout_above.
    – tim_taller
    1 сен 2014 в 13:33
  • Я прошу прощения, но как раз я в этом не силён, не могли бы вы дать код пример, как это выглядит? Конкретно про "layout_alignParentBottom, у Listview уберите внешний слой (он не нужен) и сделайте ему layout_above."
    – BORSHEVIK
    1 сен 2014 в 13:36

1 ответ 1

1

Теперь кнопки всегда видны, скролится только ListView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<ListView
        android:id="@+id/activity_main_listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/layout_btns">
</ListView>

<LinearLayout
        android:id="@+id/layout_btns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <Button
                android:id="@+id/activity_main_start"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Start"/>

        <Button
                android:id="@+id/activity_main_stop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Stop"/>

    </LinearLayout>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <Button
                android:id="@+id/activity_main_clear"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Clean"/>

        <Button
                android:id="@+id/activity_main_refresh"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Refresh"/>

    </LinearLayout>

</LinearLayout>

</RelativeLayout>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.