I am trying to have two list layout inside a Scrollview. I am using Nested scrollview for that two list layout. Scrollview is working for the second list layout but scroll view is not working for the first layout. Parent Scrollview is working as well. The issue with the first listview. Scrollview for the first listview is not working. where am I doing wrong here

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:orientation="vertical">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">

            <LinearLayout

                android:id="@+id/slistLayout1"
                android:layout_weight="4"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                >



                <ListView
                    android:id="@+id/pListView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="4"
                    android:descendantFocusability="blocksDescendants"
                    android:fadeScrollbars="false"
                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbarStyle="insideInset"
                    android:clickable="true"
                    android:focusable="true" >
                </ListView>

            </LinearLayout>

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


        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">

            <LinearLayout

                android:id="@+id/slistLayout2"
                android:layout_weight="4"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                >



                <ListView
                    android:id="@+id/pListView2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="4"
                    android:descendantFocusability="blocksDescendants"
                    android:fadeScrollbars="false"

                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbarStyle="insideInset"
                    android:clickable="true"
                    android:focusable="true" >
                </ListView>

            </LinearLayout>

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




        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/back"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/footer"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/cross"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/dcr_online"/>





        <Button
            android:id="@+id/backbt"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/add_button_selector"
            android:layout_marginBottom="5dp"
            android:gravity="center"
            android:hapticFeedbackEnabled="true"
            android:onClick="finishActivity"
            android:soundEffectsEnabled="true"
            android:text="&lt;"
            android:textColor="#FFF"
            android:textSize="25sp"
            />




    </LinearLayout>



</ScrollView>

1 Answers

1
Nikunj Sorathiya On

Please try this. I hope you can usefully.

Please use custom ListView.

Custom ListView

public class MyCustomListView extends ListView {

    public MyCustomListView(Context context) {
        super(context);
    }

    public MyCustomListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyCustomListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int heightSpec;

        if (getLayoutParams().height == LayoutParams.FILL_PARENT) {
            heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        } else {
            heightSpec = heightMeasureSpec;
        }

        super.onMeasure(widthMeasureSpec, heightSpec);
    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout

        android:id="@+id/slistLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <your_packagename.MyCustomListView
            android:id="@+id/pListView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:clickable="true"
            android:descendantFocusability="blocksDescendants"
            android:fadeScrollbars="false"
            android:focusable="true"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideInset" />


        <your_packagename.MyCustomListView
            android:id="@+id/pListView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:clickable="true"
            android:descendantFocusability="blocksDescendants"
            android:fadeScrollbars="false"
            android:focusable="true"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideInset" />


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/back"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/footer"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/cross"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/dcr_online"/>





        <Button
            android:id="@+id/backbt"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/add_button_selector"
            android:layout_marginBottom="5dp"
            android:gravity="center"
            android:hapticFeedbackEnabled="true"
            android:onClick="finishActivity"
            android:soundEffectsEnabled="true"
            android:text="&lt;"
            android:textColor="#FFF"
            android:textSize="25sp"
            />


    </LinearLayout>


</ScrollView>