Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestedScrollView inside NestedScrollview not scrolling

Tags:

android

I know this question was around A LOT , but i tried almost all solutions , even the magic solution apparently didn't work for me!: (The Parent is NestedScrollview with among childerns there is another NestedScrollview)

    parent.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            Log.v(TAG,"PARENT TOUCH");
            child.getParent().requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });

    child.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event)
        {
            Log.v(TAG,"CHILD TOUCH");
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

on Logcat i get "PARENT TOUCH" and "CHILD TOUCH" but Chidl doesn't scroll! weirdly this solution and others works for others and not me

This is my xml structure: (PS: i would love to try your solutions) (AFTER THE EDIT

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">
       <NestedScrollView
            android:layout_width="match_parent"
            android:id="@+id/parentscrollview"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">


            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_marginTop="20dp"
                android:textSize="15sp"
                android:layout_height="wrap_content"
                android:text="txt" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="txt2"
                android:textSize="15sp"
                android:layout_below="@+id/textView"
                android:id="@+id/textView2"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text=""
                android:textSize="15sp"
                android:layout_below="@+id/textView2"
                android:id="@+id/textView4"
                />


            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_below="@+id/textView4"
                android:id="@+id/autocainatiner"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="6dp"
                    android:textSize="15sp"
                    android:layout_marginTop="20dp"
                    android:textAllCaps="true"
                    android:text="Please Add/chose the observed clinical features :"
                    />

                <com.mycardboarddreams.autocompletebubbletext.MultiSelectEditText
                    android:id="@+id/auto_text_complete"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/black"
                    android:textStyle="bold"
                    android:padding="5dp"
                    android:background="#FFEEEEEE"/>

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


                <Button
                    android:id="@+id/btnPlanet"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:onClick="blahblah"
                    android:text="Enter" />
                </RelativeLayout>


            </LinearLayout>

            <NestedScrollView
                android:layout_width="match_parent"
                android:id="@+id/scrollframe"
                android:layout_below="@+id/autocainatiner"
                android:fillViewport="true"
                android:layout_height="200dp">
                <FrameLayout
                    android:id="@+id/auto_list_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimaryDark"/>
            </NestedScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/scrollframe"
                android:orientation="vertical"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="40dp"
                    android:textSize="16sp"
                    android:textAllCaps="true"
                    android:textStyle="bold"
                    android:gravity="center_horizontal"
                    android:text="Suggested Diganosi list (Please Click on suggested diseases for more infos)"
                    android:id="@+id/textView3"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:text="Suggested Diganosi list (Please Click on suggested diseases for more infos)"
                    android:layout_marginTop="25dp"
                    android:textAllCaps="true"
                    android:id="@+id/diagnosis"
                    />

                <FrameLayout
                    android:id="@+id/auto_list_container2"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:visibility="gone"
                    android:background="@color/colorPrimaryDark"/>

            </LinearLayout>


            </RelativeLayout>
        </NestedScrollView>

    </RelativeLayout>
like image 587
Zouhair Avatar asked Aug 17 '26 01:08

Zouhair


1 Answers

Solved it by creating :

public class NoInterceptScrollView extends ScrollView {

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

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }

}

and use it as parent class ..and changes the both nestedscrollview to scrollview + i removed the code for disable parent touch ...

like image 50
Zouhair Avatar answered Aug 18 '26 17:08

Zouhair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!