我正在使用 a NestedScrollWebView
(受 影响很大NestedScrollView
),它解决了许多与在 a 中使用 a 相关的已知 问题。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>
NestedScrollWebView
与AppBarLayout
和滚动标志配合得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...
方法的事实有关。根据文档:MotionEvent
super.onTouchEvent()
嵌套预滚动事件是嵌套滚动事件,触摸拦截是触摸。
dispatchNestedPreScroll
为嵌套滚动操作中的父视图提供了在子视图使用之前使用部分或全部滚动操作的机会。
现在我必须弄清楚如何返工NestedScrollWebView
以正确处理这些方法。