Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ScrollView Intercepts Clicks, should not do that

I have a view with an onClickListener inside of a scrollview. The view should react on clicks, but the scrollview interpretes almost all touches as ACTION_MOVE and intercepts the touch events, so i cannot click the view.

I have modified my scrollview as follows (because it is in a viewpager and needs to disable scrolling the viewpager)

@Override
public boolean onInterceptTouchEvent(MotionEvent p_event) {
    if (p_event.getAction() == MotionEvent.ACTION_MOVE) {
        return true;
    }
    return super.onInterceptTouchEvent(p_event);
}

@Override
public boolean onTouchEvent(MotionEvent p_event) {
    if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) {
        getParent().requestDisallowInterceptTouchEvent(true);
    }
    return super.onTouchEvent(p_event);
}

How can I change the sensitivity of the ScrollView to not register the tiniest movements as ACTION_MOVE and pass the touch events to its children?

thanks for your help!

like image 244
A. Steenbergen Avatar asked Mar 15 '26 06:03

A. Steenbergen


1 Answers

Nevermind, I fixed it! The first part is not necessary, if you modify the code as follows it works fine:

@Override
public boolean onInterceptTouchEvent(MotionEvent p_event) {
    /*if (p_event.getAction() == MotionEvent.ACTION_MOVE) {
        return true;
    }*/
    return super.onInterceptTouchEvent(p_event);
}

@Override
public boolean onTouchEvent(MotionEvent p_event) {
    if (p_event.getAction() == MotionEvent.ACTION_MOVE && getParent() != null) {
        getParent().requestDisallowInterceptTouchEvent(true);
    }
    return super.onTouchEvent(p_event);
}
like image 193
A. Steenbergen Avatar answered Mar 16 '26 22:03

A. Steenbergen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!