L. Swifter L. Swifter - 1 year ago 122
Android Question

Collision occurred in html page horizontal scroll and recyclerview vertical scroll

I have a

in my
, and the
loaded a html page. The part of the page can be horizontal scrolled, but when I horizontal scroll, the
take the touch event easily and start to scroll vertically.

How can I solve this ?

Answer Source

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();
            case MotionEvent.ACTION_MOVE:
                if (Math.abs(event.getY() - downY) < touchSlop && Math.abs(event.getX() - downX) > touchSlop) {
                    scrollFlag = true;
    if (event.getAction() == MotionEvent.ACTION_UP)
        scrollFlag = false;

    return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download