SwipeRefreshLayout不拦截NestedScrollingChild的MotionEvent

问题描述 投票:8回答:1

我正在使用NestedScrollWebView(受NestedScrollView影响很大),它解决了许多known issues与在WebView使用CoordinatorLayout有关。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="enterAlways|scroll|snap">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:titleTextAppearance="@style/TextAppearance.AppCompat.Subhead"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_gravity="bottom"
                android:visibility="gone"
                style="@style/Widget.AppCompat.ProgressBar.Horizontal"/>

        </FrameLayout>

    </android.support.design.widget.AppBarLayout>

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

        <com.example.app.widget.NestedScrollWebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

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

</android.support.design.widget.CoordinatorLayout>

NestedScrollWebViewAppBarLayoutenterAlways|scroll|snap滚动标志很好用,但与SwipeRefreshLayout不太好。


我从NestedScrollWebView中删除了以下行:

setOverScrollMode(WebView.OVER_SCROLL_NEVER);

这样可以确保视图不会显示在滚动指示器上。我想要显示滚动指示符,但即使启用了过度滚动,也不会出现以下情况。


根据我的理解,SwipeRefreshLayout应该拦截导致刷新指示符被拖动的任何触摸事件(基于其onInterceptTouchEvent()的实现)。 SwipeRefreshLayout也否认任何启用了嵌套滚动的孩子的requestDisallowInterceptTouchEvent();这对NestedScrollWebView来说是真实的。因此,这些事件应该在following manner中处理:

如果从onInterceptTouchEvent()返回true,则先前处理触摸事件的子视图将接收ACTION_CANCEL,并且从该点开始的事件将被发送到父级的onTouchEvent()方法以进行常规处理。

相反,我看到的行为是SwipeRefreshLayout确实监视NestedScrollWebView的触摸事件,但它实际上从未拦截它们。事实证明,NestedScrollWebView从未接受过ACTION_CANCEL触摸事件,并且即使SwipeRefreshLayout指标被拖下来,它仍继续接收后续事件。

这在以下屏幕截图中进行了演示;它显示了SwipeRefreshLayout的指标以及同时显示的WebView的滚动指示。

overscroll and refresh indicator shown in tandem

我无法弄清楚为什么会这样。正如我之前提到的,SwipeRefreshLayout应该适用于任何已启用嵌套滚动的视图,但由于某种原因它在这种情况下不起作用。可能是什么问题?


Update

我认为它与qazxsw poi处理qazxsw poi方法的方式有关,并且它总是将整个NestedScrollWebView传递给dispatchNestedPre...方法。根据MotionEvent

嵌套的预滚动事件是嵌套滚动事件触摸拦截的触摸。 super.onTouchEvent()为嵌套滚动操作中的父视图提供了在子视图使用之前使用部分或全部滚动操作的机会。

现在我必须弄清楚如何重写documentation来正确处理这些方法。

android swiperefreshlayout android-nestedscrollview android-touch-event
1个回答
0
投票

希望您从新发布的接口中获得一些解决方案:

dispatchNestedPreScroll接口:

NestedScrollingChild2接口:

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.