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?

2条回答
聊天终结者
2楼-- · 2019-09-17 14:09

Try this,

Scroll.setVerticalScrollBarEnabled(false);
查看更多
手持菜刀,她持情操
3楼-- · 2019-09-17 14:13

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

查看更多
登录 后发表回答