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

i have put these in Relative Layout..I have tried using ScrollView but it doesnt work . What i want is that a Submit button should be shown below Listview and when the list grows and goes offscreen the activity becomes scrollable and button should be shown below the end of listview.

Jack
  • 3
  • 2

4 Answers4

0

For the behaviour you want, it will be better if you used a RecyclerView instead of a ListView and let it be inside a NestedScrollView, then enable nestedScrolling attribute on the RecyclerView. This way, you RecyclerView will behave like a long list and all views below it will only be visible after the list has been exhausted. Check the answers in this link to see how others implemented it.

0

So for this you have to put your List and button inside NestedScrollView, but the Nestedscrollview has supported only a single child so firstly you have to put your List and button inside a Layout and then put the layout inside the NestedScrollView, You may refer the below code:

<?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>
Manoj Kumar
  • 332
  • 1
  • 7
0

Add ScrollView/NestedScrollView as a parent layout and add views inside scroll view (ListView and Button )

Try This Code:

    <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 >
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0

Make the hight of listView as fixed and then put the button below it.

Kuldeep Rathee
  • 282
  • 2
  • 7