L. Swifter L. Swifter - 3 months ago 29
Android Question

Collision occurred in html page horizontal scroll and recyclerview vertical scroll

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 ?

Answer

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:

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;
});