Android的smoothScrollTo不调用onScrollStateChanged [英] Android smoothScrollTo not invoking onScrollStateChanged

查看:1330
本文介绍了Android的smoothScrollTo不调用onScrollStateChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 smoothScrollBy()滚动到一个的ListView 的特定位置。我想,当的ListView 做滚动到它与当前的 onScrollStateChanged()事件是集成到被通知发射了用户滚动时,用他们的手指。

I am using smoothScrollBy() to scroll to a specific position in a ListView. I would like to be notified when the ListView is done scrolling to integrate it with the current onScrollStateChanged() event that is fired off when the user scrolls with their finger.

目前我使用的是定时器的平滑滚动的时间后运行100毫秒,而不是作为事件驱动的,同时我也会preFER。

Currently I'm using a Timer that runs 100ms after the duration of the smooth scroll, but that is not as event driven as I would prefer.

推荐答案

如果您已实现OnScrollListener您的列表视图,你可以看的ScrollState改变时。使用一个全球性的布尔(isScrolling)设置为true,当你调用smoothScrollBy(),然后将其设置为false,一旦OnScrollListener注册SCROLL_STATE_IDLE的ScrollState。

If you have implemented the OnScrollListener for your listview you can watch for when the ScrollState changes. Use a global boolean (isScrolling) set to true when you call smoothScrollBy() and then set it to false once the OnScrollListener registers a ScrollState of SCROLL_STATE_IDLE.

sidebar1.smoothScrollToPositionFromTop(currentPosition, 0, 500);
isScrolling = true;

sidebar1.setOnScrollListener(new OnScrollListener() {

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
        isScrolling = false;
    }

}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

}
});

这篇关于Android的smoothScrollTo不调用onScrollStateChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆