Android scrolling canceles Webview move events

134 Views Asked by At

I have Android activity with NestedScrollView and inside it I have Webview with some html and jQuery script.

<FrameLayout 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">

    <android.support.design.widget.CoordinatorLayout
        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:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/main_scroller"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

... some other components ...

                <WebView
                    android:id="@+id/web_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
   
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

In this jQuery script I'm listening for events 'touchstart', 'touchmove' and 'touchend' on one of the element in html. When I move finger horizontally on this element, events are triggered. However, when i move finger 1px up or down, Android native scrolling is triggered and my native code (listener setOnTouchListener) is triggered too:

view.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d(TAG, "touched");
        return false;
    }
});

but my jQuery listeners in webview are not triggered. It looks like Android doesn't propagate touch events to webview while scrolling in NestedScrollView.

If I change NestedScrollView for FrameLayout (or something else not scrollable), everything is working perfectly (when I move fingers vertically, jQuery touchmove event is triggered).

I was trying to return true in Android onTouch event, it stopped to scroll the page, but webview was not receiving touch events. ScrollView behaves the same as NestedScrollView.

Do you have any idea, how to propagate touch events to webview and still using ScrollView? Thank you.

0

There are 0 best solutions below