最近项目里需要做评价内容的循环滚动显示,一开始想到的就是定时器。后来查了资料才知道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

相关文章:

  • 2021-08-07
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案