ListView的自动循环滚动显示

最近项目里需要做评价内容的循环滚动显示,一开始想到的就是定时器。后来查了资料才知道ListView里面有个函数smoothScrollToPosition(position),瞬间觉得简单了很多。首先我们用ListView加载所有数据,设置高度让它只显示一条,然后设置定时,调用上面这个函数进行滚动。代码如下:

autoUpdate = new Timer();
autoUpdate.schedule(new TimerTask(){
    @Override
    public void run(){
        runOnUiThread(new Runnable(){
           public void run(){
             index +=1;
             if(index >= list_review.getCount()) {
                 index = 0;
 
               }
              list_review.smoothScrollToPosition(index);
          }
        });
  }
}, 0,3000);

这样就可以实现循环滚动了。

原文:http://blog.it985.com/12770.html

原文地址:https://www.cnblogs.com/tc310/p/4868778.html