[英]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.