2017-02-20 2 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); 
} 
関連する問題