android: AbsListView.OnScrollListener SCROLL_STATE_IDLE 在 SCROLL_STATE_TOUCH_SCROLL 之后不会被调用(2.1 版)
我的 Android 版本 2.1 有问题。它看起来像一个错误。
我将一个 OnScrollListener
附加到我的 listView 上。
我正在使用方法 onScrollStateChanged(AbsListView view, int scrollState)
来监视列表视图的滚动状态。
滚动状态可以采用 3 个值(取自文档):
- SCROLL_STATE_FLING:用户有 以前一直使用滚动 触摸并进行了一次投掷。这 动画现在正在滑行停止
- SCROLL_STATE_IDLE:视图没有 滚动。注意浏览列表 使用轨迹球算作 处于空闲状态,因为这些 过渡不是动画的。
- SCROLL_STATE_TOUCH_SCROLL:用户 正在使用触摸滚动,并且他们的 手指仍在屏幕上
我假设 SCROLL_STATE_IDLE 将始终在其他两种状态之一之后传递。 除了 android 版本 2.1 之外,这始终是正确的。 SCROLL_STATE_IDLE 在 SCROLL_STATE_TOUCH_SCROLL 之后未传递 如果您通过触摸停止快速滑动而不是让滚动自行停止,也会出现此问题。 这种奇怪的行为使我的 listView 处于不稳定的状态。
有人有同样的问题吗? 关于“不太肮脏”的解决方法的建议?
I have a problem with android version 2.1. It looks like a bug.
I attached an OnScrollListener
to my listView.
I'm using the method onScrollStateChanged(AbsListView view, int scrollState)
for monitoring the scroll's state of my listview.
The scrollstate could assume 3 value (taken from the documentation):
- SCROLL_STATE_FLING: The user had
previously been scrolling using
touch and had performed a fling. The
animation is now coasting to a stop - SCROLL_STATE_IDLE:The view is not
scrolling. Note navigating the list
using the trackball counts as being
in the idle state since these
transitions are not animated. - SCROLL_STATE_TOUCH_SCROLL:The user
is scrolling using touch, and their
finger is still on the screen
I assume that the SCROLL_STATE_IDLE will always be passed after one of other two states.
It's always true excepted for android version 2.1.
SCROLL_STATE_IDLE is not passed after SCROLL_STATE_TOUCH_SCROLL
The problem happens also if you stop the fling by a touch instead of let the scroll stop by itself.
This strange behaviour leaves my listView in an unconsistate state.
Someonelse has the same problem?
Suggestion for a "not-so-dirty" work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这个案例中存在一个已注册的错误。
http://code.google.com/p/android/issues/detail ?id=5086
I think there is a bug that has been registered for this case.
http://code.google.com/p/android/issues/detail?id=5086
我在 2.2 上遇到了类似的问题。
如果列表足够大,并且我向下滚动,当我的手指在屏幕上时,我会首先得到 CROLL_STATE_TOUCH_SCROLL 。当我的手指离开屏幕时,我得到了 SCROLL_STATE_FLING。当我的视图停止移动时,我得到了 SCROLL_STATE_IDLE。
但是,如果在滚动过程中,它到达“视图顶部”或“底部”,我只会滚动/滑动值,而不会处于空闲状态。
我检查了 Romain Guy 的 Shelves 项目,他的实现在 2.2.x 上遇到了同样的问题,我想知道他是否注意到了。
我还没有尝试过 2.3.x
I got a similar issue on 2.2.
If the list is big enough, and I scroll down up, I got first CROLL_STATE_TOUCH_SCROLL while my finger is on the screen. When my finger leave the screen I got the SCROLL_STATE_FLING. When my view has stopped moving I got the SCROLL_STATE_IDLE.
But, if during scroll, it reaches either View Top or Bottom, I only scroll/fling values and never the idle.
I checked out Shelves project from Romain Guy and his implementation suffer the same issue on 2.2.x I'm wondering if he had noticed yet.
I haven't tried yet with 2.3.x
我找到了一些解决方法(至少对于 API 级别 9+,我仍然看到该错误)。我正在使用 GridView,但我相信这也适用于 ListView。
我正在使用 GridView 的子类,在其中检测过度滚动(顶部或底部):
然后,在 CustomGridView 的 OnScrollListener 中,我有:
现在,当我检查
OnScrollListener.SCROLL_STATE_IDLE
时,我还要检查是否!gridView.isOverScrolled()
。我不确定这是否可以修复您的特定用例,但希望您可以使用附加信息来确定您当前的状态,尽管存在错误。I found something of a workaround for this (at least for API level 9+, where I'm still seeing the bug). I'm using a GridView, but I believe this should also work for ListView.
I'm using a subclass of GridView where I am detecting the overscroll (top or bottom):
Then, in my OnScrollListener of CustomGridView, I have:
Now when I'm checking for
OnScrollListener.SCROLL_STATE_IDLE
, I also check if!gridView.isOverScrolled()
. I'm not sure if that fixes your specific use cases, but hopefully you can use the additional piece of info to determine your current state despite the bug.我遇到了同样的问题,并在 DeRagan 提到的错误列表上发布了解决方法:
链接
I have had this same problem and posted a workaround on the bug list mentioned by DeRagan:
Link