简体   繁体   English

滚动到Android Scrollview中的特定位置时如何取消滚动?

[英]How to cancel scrolling when scroll to a specific position in Android Scrollview?

I have a problem while scrolling in Scrollview. 在Scrollview中滚动时出现问题。 I would like to cancel scrolling immediately when I've scrolled to a specific position (like end of scrollview). 我想在滚动到特定位置时立即取消滚动(例如scrollview的结尾)。 That means my finger is still held on screen, but Scrollview can't scroll anymore. 这意味着我的手指仍然停留在屏幕上,但是Scrollview无法再滚动。 How can I accomplish this? 我该怎么做?

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
   if (!mScrollable) return false;
     else return super.onInterceptTouchEvent(ev);
}

If you want to cancel/stop scroll when you have reached particular position, you can use smoothScrollToPosition(int pos), where pos is the adapter position. 如果要在到达特定位置时取消/停止滚动,则可以使用smoothScrollToPosition(int pos),其中pos是适配器的位置。

Also to make it a smooth experience for user, you can tell the listview to post it when ui thread is free: 另外,为使用户获得流畅的体验,您可以告诉uiview空闲时将listview发布给用户:

getListView().post(new Runnable() {
    @Override
    public void run() {
        getListView().smoothScrollToPosition(pos);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android listview在scrollview中,listview在scrollview滚动到特定位置时滚动 - Android listview in scrollview, listview scroll when scrollview scrolled specific position Android:如何在滚动Horizo​​ntalScrollView时禁用ScrollView的垂直滚动? - Android: How to disable vertical scroll of ScrollView when scrolling a HorizontalScrollView? Android - 滚动停止后如何滚动到 ScrollView 的开头或结尾? - Android - How to Scroll to Begining or end of ScrollView after Scrolling Stopped? Android ScrollView滚动到特定行 - Android ScrollView Scroll to specific row Android:如果不通过特定的ScrollView完成操作,如何忽略滚动更改? - Android: how can I ignore scrolling changes if not done by a specific ScrollView? 如何以编程方式将ListView滚动到android中的特定位置 - how to scroll listview to specific position in android programmatically 如何在开始/结束滚动时挂接到Android ScrollView? - How to hook into Android ScrollView when it starts/ends scrolling? Android Listview滚动到特定位置 - Android Listview scrolling to a specific position Android:如何在顶部滚动 ScrollView - Android: How to scroll ScrollView in top 如何使用数据绑定滚动到ScrollView上的位置? - How to scroll to position on ScrollView using databinding?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM