2017-02-20 110 views
1

我有这个回收站视图作为一个自动收报机,自动滚动首先正常工作,但经过一段时间它变得奇怪(来回)和回收视图卡住一个项目没有平滑的滚动,任何人都可以帮助我。水平回收站视图自动滚动错误

这是我的布局管理器:

LinearLayoutManager layoutManager = new LinearLayoutManager(HomeActivity.this, LinearLayoutManager.HORIZONTAL, false) { 
     @Override 
     public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { 
      LinearSmoothScroller smoothScroller = new LinearSmoothScroller(HomeActivity.this) { 
       private static final float SPEED = 5500f;// Change this value (default=25f) 
       @Override 
       protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { 
        return SPEED/displayMetrics.densityDpi; 
       } 
      }; 
      smoothScroller.setTargetPosition(position); 
      startSmoothScroll(smoothScroller); 
     } 

    }; 
    rvTicker.setLayoutManager(layoutManager); 

这是我的自动滚动功能:

public void autoScroll(){ 
    speedScroll = 0; 
    handler = new Handler(); 
    runnable = new Runnable() { 
     int count = 0; 
     @Override 
     public void run() { 
      if(count == tickerAdapter.getItemCount()) 
       count = 0; 
      if(count < tickerAdapter.getItemCount()){ 
       rvTicker.smoothScrollToPosition(++count); 
       handler.postDelayed(this,speedScroll); 
      } 
     } 
    }; 
    handler.postDelayed(runnable,speedScroll); 
} 

回答

0

解决了,我调整了自动滚屏功能:

public void autoScroll(){ 
    speedScroll = 0; 
    handler = new Handler(); 
    runnable = new Runnable() { 
     int count = 0; 
     @Override 
     public void run() { 
      if(count == tickerAdapter.getItemCount()) 
       count = 0; 
      else { 
       if(count < tickerAdapter.getItemCount()){ 
        rvTicker.smoothScrollToPosition(++count); 
        handler.postDelayed(this,speedScroll); 
       }else { 
        count = 0; 
       } 
      } 
      Log.wtf("tickerAdapter.getItemCount()", tickerAdapter.getItemCount()+""); 
      Log.wtf("count", count+""); 
      Log.wtf("++count", ++count+""); 
      Log.wtf("==============","============="); 
     } 
    }; 
    handler.postDelayed(runnable,speedScroll); 
}