内嵌一个 WebView 时,希望 WebView 处理所有手势,IndicatorView 响应滑动。
很奇怪的是:
照理讲在Fragment中设置webview.getParent(). requestdisallowintercepttouchevent()
就能够解决问题,但测试无效。
重写WebView的onInterceptTouchEvent()
在其中调用就能解决。
XML 布局
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="140dp"
android:background="@android:color/transparent">
<FrameLayout
android:id="@+id/bottom_sheet_fg_room"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="true"
app:behavior_peekHeight="36dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<WebView
android:id="@+id/game_view_fg_room"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<io.liuqiang@agora.io.uiwidget.IndicatorView
android:id="@+id/indicator_sheet_fg_room"
android:layout_width="72dp"
android:layout_height="36dp"
android:layout_gravity="top|center_horizontal" />
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Fragment中调用requestDisallowInterceptTouchEvent()
效果
父布局还是会拦截事件分发,优先处理。
WebView 仅在父布局不拦截的时候才会响应自己的业务逻辑。

完美效果: 重写onInterceptTouchEvent()
事件分发完全由自己处理
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
super.onInterceptTouchEvent(ev);
getParent().requestDisallowInterceptTouchEvent(true);
return true;
}

网友评论