-1

I have a problem with a scrollView and a listView in android. My Scrollview does not work. The last item does not appear and the listView take the whole screen.

I don't know why and i have not found any answer yet.

My xml file :

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">

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

        <TextView
            android:id="@+id/additionName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:text="Your Order"
            android:textSize="30dp" />

        <ListView
            android:id="@+id/additionListviewProducts"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/additionName"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            android:isScrollContainer="false"/>

        <View
            android:id="@+id/additionLineSeparator"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/additionListviewProducts"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#000000" />

        <TextView
            android:id="@+id/additionTotal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/additionLineSeparator"
            android:layout_marginRight="20dp"
            android:layout_marginTop="5dp"
            android:gravity="right"
            android:text="100 euros"
            android:textSize="20sp" />

        <Button
            android:id="@+id/validatePayment"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/additionTotal"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:background="@drawable/button_style"
            android:text="Order"
            android:textSize="25sp" />

    </LinearLayout>
</ScrollView>
Amit Anand
  • 1,225
  • 1
  • 16
  • 40
Maxouille
  • 2,729
  • 2
  • 19
  • 42
  • possible duplicate of [Android list view inside a scroll view](http://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view) – Illegal Argument Aug 04 '14 at 09:37

3 Answers3

2

Putting a ListView inside ScrollView without breaking the ScrollView is not naturally possible. The easy way to make it happen anyway is to disable the ListView view recycling functionality, which will affect performance. If you still need it (there are some use cases), see this answer: How can I put a ListView into a ScrollView without it collapsing?

Community
  • 1
  • 1
0101100101
  • 5,786
  • 6
  • 31
  • 55
0

Put your whole ScrollView in RelativeLayout with android:orientation="vertical". Thanks!

0

Try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/relativeLayout1212" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

 <ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">

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

        <TextView
            android:id="@+id/additionName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:text="Your Order"
            android:textSize="30dp" />

        <ListView
            android:id="@+id/additionListviewProducts"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/additionName"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            android:isScrollContainer="false"/>

        <View
            android:id="@+id/additionLineSeparator"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/additionListviewProducts"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#000000" />

        <TextView
            android:id="@+id/additionTotal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/additionLineSeparator"
            android:layout_marginRight="20dp"
            android:layout_marginTop="5dp"
            android:gravity="right"
            android:text="100 euros"
            android:textSize="20sp" />

        <Button
            android:id="@+id/validatePayment"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/additionTotal"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:background="@drawable/button_style"
            android:text="Order"
            android:textSize="25sp" />

    </LinearLayout>
</ScrollView>
</RelativeLayout>

Hope this may help you!

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28