Issue
I have a WebView
in my RecyclerView
, and the WebView
loaded a html page. The part of the page can be horizontal scrolled, but when I horizontal scroll, the RecyclerView
take the touch event easily and start to scroll vertically.
How can I solve this ?
Solution
Finally, I have figured out the solution about my question. The part of the WebView
is in the top of the view. so I use this to intercept the touch event:
float touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop()
webView.setOnTouchListener((View v, MotionEvent event) -> {
if (!scrollFlag && event.getY() < getHeight() / 2) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(event.getY() - downY) < touchSlop && Math.abs(event.getX() - downX) > touchSlop) {
getParent().requestDisallowInterceptTouchEvent(true);
scrollFlag = true;
}
break;
}
}
if (event.getAction() == MotionEvent.ACTION_UP)
scrollFlag = false;
return false;
});
Answered By - L. Swifter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.