9

我正在使用 a NestedScrollWebView(受 影响很大NestedScrollView),它解决了许多与在 a 中使用 a 相关的已知 问题WebViewCoordinatorLayout

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

NestedScrollWebViewAppBarLayout和滚动标志配合得enterAlways|scroll|snap很好,但与SwipeRefreshLayout.


我从以下行中删除了NestedScrollWebView

setOverScrollMode(WebView.OVER_SCROLL_NEVER);

这确保视图不会显示在滚动指示器上。我希望出现过度滚动指示器,但即使启用了过度滚动,以下情况也不应该发生。


据我了解,SwipeRefreshLayout应该拦截任何导致刷新指示器被拖动的触摸事件(基于其实现onInterceptTouchEvent())。SwipeRefreshLayout还拒绝任何requestDisallowInterceptTouchEvent()启用了嵌套滚动的孩子;对于NestedScrollWebView. 因此,应按以下方式处理这些事件:

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

相反,我看到的行为是SwipeRefreshLayout确实监视了触摸事件,NestedScrollWebView但它从未真正拦截它们。NestedScrollWebView正如从不接收触摸事件的事实所证明的那样,ACTION_CANCEL即使SwipeRefreshLayout指示器被向下拖动,它也会继续接收后续事件。

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

串联显示的过度滚动和刷新指示器

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


更新

我认为这与NestedScrollWebView处理方法的方式以及它总是将整个传递给dispatchNestedPre...方法的事实有关。根据文档MotionEventsuper.onTouchEvent()

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

现在我必须弄清楚如何返工NestedScrollWebView以正确处理这些方法。

4

1 回答 1

0

希望您能从新发布的界面中获得一些解决方案:

NestedScrollingChild接口:

NestedScrollingParent接口:

谢谢你。

于 2019-02-15T07:23:14.593 回答