and*_*per 5 android scroll android-listview android-gridview android-adapterview
我正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)
代码通常有效,但在某些情况下,滚动开始需要很长时间.
事实上,似乎我越是开启和关闭,我就越需要等待它开始自动滚动.
我认为只有当我滚动回到顶部时才会出现此问题.当adapterView稍微滚动时,它工作得很好.
因为我无法找到如何获取adapterView的当前滚动值,我无法找到如何解决此问题.
我该怎么做才能解决这个问题?还有其他选择吗?
您可以开始滚动SCROLLING_RUNNABLE.run();
更新或者您可以使用动画:
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
// scroll the list
}
};
Run Code Online (Sandbox Code Playgroud)
和clearAnimation()停止。
| 归档时间: |
|
| 查看次数: |
3350 次 |
| 最近记录: |