无限自动滚动的ListView与滚动速度控制 [英] Infinite Auto Scroll ListView with Scroll Speed Controlled
问题描述
我一直在那里一直没有用户交互自动滚动的ListView
的想法,这是绝对可行例如使用了Android的API smoothScrollToPositionFromTop 的
我已实施的ListView BaseAdapter
它加载的项目永远(几乎)得到一个非停止自我重复的ListView
我想在这里实现的是让我的的ListView
以一定的速度(慢),使项目清晰可读永远的滚动而滚动下来,我还不确定是否的ListView
是我最好的选择在这里。
下面是什么,我试图做一个片段。结果是有点好,但它不够光滑,我能感觉到的ListView闪烁。
我需要提高的平滑度,效率和控制速度
新主题(新的Runnable(){ @覆盖
公共无效的run(){
INT listViewSize = mListView.getAdapter()getCount将()。 对于(INT指数= 0;指数 - LT; listViewSize;指数++){
mListView.smoothScrollToPositionFromTop(mListViewA.getLastVisiblePosition()+ 100,0,6000);
尝试{
//它有助于滚动保持顺利地进行(通过实验)
视频下载(60);
}赶上(InterruptedException的E){ }
}
}
})。开始();
我建议,thath适配器有效方式实现。
所以这code只是滚动列表视图
你需要尝试的另一个变量的值
最终长totalScrollTime = Long.MAX_VALUE; //总滚动的时间。我认为300 000 000年代是接近enouth到无穷远。如果没有足够多的你可以onFinish重启定时器()最终诠释scrollPeriod = 20; //每20毫秒scoll意志发生了。流畅的较小值最终诠释heightToScroll = 20; //将滚动到每次20像素。流畅滚动较小的值listView.post(新的Runnable(){
@覆盖
公共无效的run(){
新CountDownTimer(totalScrollTime,scrollPeriod){
公共无效onTick(长millisUntilFinished){
listView.scrollBy(0,heightToScroll);
} 公共无效onFinish(){
//你可以添加code在这里重新开始计时
}
}。开始();
}
});
I have been working on a ListView
idea where it keeps scrolling automatically with no user interaction and that is absolutely doable using the android APIs for instance smoothScrollToPositionFromTop.
I have implemented ListView BaseAdapter
where it load items forever (almost) to get a non stopping self repeated ListView
.
What I want to achieve here is to keep myListView
scrolling forever with certain speed (slow) to make items clear and readable while scrolling down, I not sure yet if ListView
is my best choice here.
below is a snippet of what I am trying to do. the result is good somehow but it's not smooth enough, I can feel the ListView flickers.
I need to improve smoothness, efficiency and control the speed
new Thread(new Runnable() {
@Override
public void run() {
int listViewSize = mListView.getAdapter().getCount();
for (int index = 0; index < listViewSize ; index++) {
mListView.smoothScrollToPositionFromTop(mListViewA.getLastVisiblePosition() + 100, 0, 6000);
try {
// it helps scrolling to stay smooth as possible (by experiment)
Thread.sleep(60);
} catch (InterruptedException e) {
}
}
}
}).start();
I suggest, thath your adapter implemented in effective way. so this code is just scrolls listview
you need to try another values of variables
final long totalScrollTime = Long.MAX_VALUE; //total scroll time. I think that 300 000 000 years is close enouth to infinity. if not enought you can restart timer in onFinish()
final int scrollPeriod = 20; // every 20 ms scoll will happened. smaller values for smoother
final int heightToScroll = 20; // will be scrolled to 20 px every time. smaller values for smoother scrolling
listView.post(new Runnable() {
@Override
public void run() {
new CountDownTimer(totalScrollTime, scrollPeriod ) {
public void onTick(long millisUntilFinished) {
listView.scrollBy(0, heightToScroll);
}
public void onFinish() {
//you can add code for restarting timer here
}
}.start();
}
});
这篇关于无限自动滚动的ListView与滚动速度控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!