kunal kunal - 1 month ago 12
Android Question

Scrollview is not scrolling at all in my UI

Here is my xml layout file in which i use scrollview and it is not working.

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">

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


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="10dp"
android:text="Edit Order"
android:layout_marginTop="5dp"
android:id="@+id/txtyourOrder"
android:textColor="@android:color/holo_green_dark" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Order"
android:layout_marginLeft="10dp"
android:textColor="@android:color/black"
android:textSize="20sp" />


<View
android:id="@+id/view1"
android:layout_below="@id/txtyourOrder"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="10dp"
android:background="@android:color/darker_gray" />

<ListView
android:layout_below="@id/view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true"
android:layout_marginTop="10dp"
android:id="@+id/listview"
android:textColor="@android:color/darker_gray" />

<TextView
android:layout_below="@id/listview"
android:id="@+id/txtAddItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="Add Items"
android:textColor="@android:color/holo_green_dark" />



<TextView
android:layout_below="@id/txtAddItems"
android:id="@+id/txtsubtotalbd"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtotal before discount"
android:textSize="12sp" />

<TextView
android:layout_below="@id/txtAddItems"
android:id="@+id/txtsubtotalbdRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:text="Rs."
android:textSize="12sp" />

<TextView
android:layout_marginLeft="10dp"
android:id="@+id/txtdiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtsubtotalbd"
android:text="Discount"
android:textSize="12sp" />

<TextView
android:id="@+id/txtdiscountRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/txtsubtotalbdRs"
android:layout_marginRight="10dp"
android:text="Rs."
android:textSize="12sp" />

<TextView
android:layout_marginLeft="10dp"
android:id="@+id/txtsubtotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtdiscount"
android:text="Subtotal"
android:textSize="12sp" />

<TextView
android:id="@+id/txtsubtotalRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/txtdiscountRs"
android:layout_marginRight="10dp"
android:text="Rs."
android:textSize="12sp" />

<TextView
android:layout_marginLeft="10dp"
android:id="@+id/txtservicefee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtsubtotal"
android:text="Service fee (0 %)"
android:textSize="12sp" />

<TextView
android:id="@+id/txtservicefeeRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/txtsubtotalRs"
android:layout_marginRight="10dp"
android:text="Rs."
android:textSize="12sp" />

<TextView
android:id="@+id/txtdeliveryfee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtservicefee"
android:text="Delivery fee"
android:layout_marginLeft="10dp"
android:textSize="12sp" />

<TextView
android:id="@+id/txtdeliveryfeeRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/txtservicefeeRs"
android:layout_marginRight="10dp"
android:text="Rs."
android:textSize="12sp" />

<EditText
android:id="@+id/edtVoucherCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtdeliveryfee"
android:layout_marginTop="10dp"
android:backgroundTint="@android:color/holo_green_dark"
android:hint="Voucher Code (Optional)" />

<TextView
android:id="@+id/txtAddVoucher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/edtVoucherCode"
android:layout_marginRight="10dp"
android:gravity="end"
android:text="Add Voucher from list"
android:textColor="@android:color/holo_green_dark" />


<View
android:layout_below="@id/txtAddVoucher"
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@android:color/darker_gray" />

<RelativeLayout
android:layout_below="@id/view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<TextView
android:id="@+id/txtTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total"
android:textColor="@android:color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/txtTotalRs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:text="Rs."
android:textColor="@android:color/black"
android:textSize="18sp" />
</RelativeLayout>

<Button
android:id="@+id/btnAddtoCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:background="@android:color/holo_green_dark"
android:drawableRight="@drawable/ic_arrow"
android:text="Proceed to Checkout"
android:textColor="@android:color/white" />
</RelativeLayout>


</android.support.v4.widget.NestedScrollView>


Please help me!

Answer

As defined here..

You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView. I strongly recommend you to simplify your layout somehow. For example you can add views you want to be scrolled to the ListView as headers or footers.

Comments