适配器视图的自动滚动(列表视图,GridView的...) [英] Auto-scrolling of AdapterView (Listview, GridView,...)
问题描述
我试图让一个AdapterView(列表视图,GridView控件,...)慢慢地自动滚动。
I'm trying to make an AdapterView (listview, gridview,...) to slowly auto scroll .
只要他愿意,用户可以切换它,它不是所有的方式确实需要移动到适配器视图的结尾。
the user can toggle it whenever he wishes, and it doesn't necessary move all the way to the end of the adapterView.
再次,我不想让适配器视图一路滚动到底因为用户应该能够取消自动滚动。
again, i DO NOT wish to make the adapterView to scroll all the way to the bottom since the user should be able to cancel the auto-scrolling.
对于这一点,我使用的下一个code:
for this, i'm using the next code:
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);
问题
的code通常工作,但在某些情况下,需要很长的时间,直到滚动开始
The problem
the code usually works, but on some cases, it takes a long time till the scrolling starts.
事实上,似乎我越开启和关闭,更多的我将不得不等待它来启动自动滚动。
in fact, it seems that the more i turn it on and off, the more i will have to wait for it to start auto-scrolling.
我想只有当我向后滚动顶端发生此问题。当适配器视图中滚动了一下它工作得很好。
i think this issue occurs only if i scroll back to the top. it works just fine when the adapterView is in scrolled a bit.
因为我不能找出如何让适配器视图当前的滚动值,我不能找出如何解决这个问题。
since i can't find out how to get the current scrolling value of the adapterView, i can't find out how to fix this issue.
我可以为了解决这个问题,怎么办?是否有其他选择吗?
What can I do in order to fix this issue ? Is there an alternative?
推荐答案
您可以开始滚动 SCROLLING_RUNNABLE.run();
更新
或者你可以使用动画:
UPDATE Or you can use animations:
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
// scroll the list
}
};
和 clearAnimation()
停止。
这篇关于适配器视图的自动滚动(列表视图,GridView的...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!