我在https://myinstance.notebook.us-east-1.sagemaker.aws/proxy/6006/
中有WebView
个。为了获得流畅的滚动体验,以便用户滚动时,RecyclerView
将负责滚动(RecyclerView
不应滚动)我在WebView
内打电话给getParent().requestDisallowInterceptTouchEvent(false);
仅一个接触点,并且正在垂直移动(上下滚动)。
webview#onTouchEvent(event)
只有一个错误,它可以正常工作,我发现在private void handleSingleFingerTouch(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = ev.getX();
y1 = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
x2 = ev.getX();
y2 = ev.getY();
// -ve param for canScrollHorizontally is to check scroll left. +ve otherwise
if (Math.abs(x1 - x2) >= Math.abs(y1 - y2)
&& canScrollHorizontally((int) (x1 - x2))) {
// scrolling horizontally. Retain the touch inside the webView.
getParent().requestDisallowInterceptTouchEvent(true);
} else {
// scrolling vertically. Share the touch event with the parent.
getParent().requestDisallowInterceptTouchEvent(false);
}
x1 = x2;
y1 = y2;
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean multiTouch = ev.getPointerCount() > 1;
if (multiTouch) {
getParent().requestDisallowInterceptTouchEvent(true);
} else {
handleSingleFingerTouch(ev);
}
return super.onTouchEvent(ev);
}
(和webview)滚动并触摸RecyclerView
的内部时,WebView
停止了滚动,如果我不会抬起手指,而是将手指放在屏幕上并尝试缩放,但Webview不会缩放,实际上它根本不会收到触摸事件。我必须抬起手指并再次触摸以进行缩放。我知道这是因为RecyclerView
不会取消,除非UI收到getParent().requestDisallowInterceptTouchEvent(false);
或CANCEL
事件。我尝试实现一个接口,该接口在发生多点触摸时调用UP
。尽管它确实被调用了,但是似乎不起作用。缩放仍然没有发生,并且getParent().requestDisallowInterceptTouchEvent(true);
内部的onTouchEvent
仍未触发。有解决的办法吗?
答案 0 :(得分:4)
因此,基本上,解决方案是覆盖recyclerView的onInterceptTouchEvent
override fun onInterceptTouchEvent(e: MotionEvent): Boolean {
// When recyclerview is scrolling this will stop scrolling and allow touch event passed to child views.
if (e.action == MotionEvent.ACTION_DOWN && this.scrollState == RecyclerView.SCROLL_STATE_SETTLING) {
this.stopScroll()
}
return super.onInterceptTouchEvent(e)
}