Android ScrollView disable Inertial scrolling

2019-09-17 13:31发布

问题:

In my activity I reference ScrollView. According to the requirements, I should disable the inertial scrolling of ScrollView. How can I do that?

回答1:

These worked form me, but I'm not sure if it is good for performance.

What I did was create a new View extending the ScrollView and override the onTouchEvent method:

@Override
public boolean onTouchEvent(MotionEvent ev) {


    switch (ev.getAction()){
        case ACTION_UP:

            return false;
        default:
            return super.onTouchEvent(ev);
    }
}

I don't know watch happens it alter the state machine that control scrolling and movement on the view, but it works.

perhaps, you should also check the source code of the ScrollView to check if there is anything important else to do.

If you wish to pursue such endeavour, here you have the source code at dispose:

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/ScrollView.java



回答2:

Try this,

Scroll.setVerticalScrollBarEnabled(false);