Как разместить кнопку под ListView в прокручиваемом действии? - PullRequest
0 голосов
/ 25 сентября 2019
<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".list1">

            <ImageView
                android:id="@+id/sinb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/left"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                />


            <ListView
                android:layout_below="@id/sinb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/listView1"
                android:layout_marginTop="30dp"
                android:layout_centerHorizontal="true"
                android:choiceMode="multipleChoice" />
            <Button
                android:id="@+id/btn1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/listView1"
                android:text="submit"/>

        </RelativeLayout>

Я поместил их в Относительную компоновку. Я пытался использовать ScrollView, но он не работает.Я хочу, чтобы кнопка «Отправить» отображалась под списком, а когда список увеличивается и выходит за пределы экрана, действие становится прокручиваемым, а кнопка должна отображаться под концом списка.

Ответы [ 4 ]

0 голосов
/ 26 сентября 2019

Сделайте высоту listView фиксированной, а затем поместите кнопку под ней.

0 голосов
/ 25 сентября 2019

Так что для этого вы должны поместить свой список и кнопку в NestedScrollView, но Nestedscrollview поддерживает только одного ребенка, поэтому сначала вы должны поместить свои List и button в макет, а затем поместитьмакет внутри NestedScrollView, Вы можете ссылаться на код ниже:

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <ImageView
        android:id="@+id/sinb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:padding="10dp"
        android:src="@drawable/left" />

    <android.support.v4.widget.NestedScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@id/sinb">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/listView1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginTop="30dp"
                tools:listitem="@layout/item_view_note"
                android:choiceMode="multipleChoice" />

            <Button
                android:id="@+id/btn1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/listView1"
                android:text="submit" />
        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>
</RelativeLayout>
0 голосов
/ 26 сентября 2019

Добавление ScrollView / NestedScrollView в качестве родительского макета и добавление представлений в представление прокрутки (ListView и кнопка)

Попробуйте этот код:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".list1">

                <ImageView
                    android:id="@+id/sinb"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/left"
                    android:padding="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginLeft="20dp"
                    />
        <android.support.v4.widget.NestedScrollView
                            android:id="@+id/navigation_nested"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:fillViewport="true"
                              android:layout_below="@+id/sinb"
                            android:overScrollMode="never">
         <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:padding="@dimen/margin_15">
                         <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/listView1"
                    android:layout_marginTop="30dp"
                    android:layout_centerHorizontal="true"
                    android:choiceMode="multipleChoice" />
                <Button
                    android:id="@+id/btn1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="submit"/>
</LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    </RelativeLayout >
0 голосов
/ 25 сентября 2019

Для поведения, которое вы хотите, было бы лучше, если бы вы использовали RecyclerView вместо ListView и оставили его внутри NestedScrollView, а затем включили атрибут nestedScrolling в RecyclerView.Таким образом, ваш RecyclerView будет вести себя как длинный список, и все представления под ним будут видны только после того, как список будет исчерпан.Посмотрите ответы по этой ссылке , чтобы увидеть, как это реализовали другие.

...