我正在尝试使用AdapterView(listview,gridview,...)来慢慢自动滚动。
用户可以随时切换它,并且不必一直移动到adapterView的末尾。
再次,我不希望将adapterView一直滚动到底部,因为用户应该可以取消自动滚动。
为此,我正在使用下一个代码:
private static final SCROLLING_RUNNABLE = new Runnable() {
@Override
public void run() {
final int duration = 10;
final int pixelsToMove = 1;
mAdapterView.smoothScrollBy(pixelsToMove, duration);
mHandler.postDelayed(this, duration);
}
};
...
// use this to turn auto-scrolling on:
mHandler.post(SCROLLING_RUNNABLE);
// use this to turn auto-scrolling off:
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
代码通常有效,但在某些情况下,滚动开始需要很长时间。
事实上,似乎越是开启和关闭它,我就越需要等待它开始自动滚动。我认为只有当我滚动到顶部时才会出现此问题。当adapterView稍微滚动时,它可以正常工作。
因为我无法找到如何获取adapterView的当前滚动值,我无法找到如何解决此问题。
我可以做些什么来解决这个问题?还有其他选择吗?
答案 0 :(得分:1)
您可以开始滚动SCROLLING_RUNNABLE.run();
UPDATE 或者您可以使用动画:
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
// scroll the list
}
};
和clearAnimation()
停止。