2016-08-31 4 views

Antwort

6

Bitte überprüfen Sie die Lösung hier. https://github.com/ritesh-bhavsar86/StockAutoScroll

ersten runnable erstellen:

final int duration = 10; 
final int pixelsToMove = 30; 
private final Handler mHandler = new Handler(Looper.getMainLooper()); 
private final Runnable SCROLLING_RUNNABLE = new Runnable() { 

    @Override 
    public void run() { 
     rv_autoScroll.smoothScrollBy(pixelsToMove, 0); 
     mHandler.postDelayed(this, duration); 
    } 
}; 

dann nach setAdapter() an die recyclerView Verwendung folgenden:

rv_autoScroll.addOnScrollListener(new RecyclerView.OnScrollListener() { 
     @Override 
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
      super.onScrolled(recyclerView, dx, dy); 
      int lastItem = layoutManager.findLastCompletelyVisibleItemPosition(); 
      if(lastItem == layoutManager.getItemCount()-1){ 
       mHandler.removeCallbacks(SCROLLING_RUNNABLE); 
       Handler postHandler = new Handler(); 
       postHandler.postDelayed(new Runnable() { 
        @Override 
        public void run() { 
         rv_autoScroll.setAdapter(null); 
         rv_autoScroll.setAdapter(madapter); 
         mHandler.postDelayed(SCROLLING_RUNNABLE, 2000); 
        } 
       }, 2000); 
      } 
     } 
    }); 
    mHandler.postDelayed(SCROLLING_RUNNABLE, 2000); 

rv_autoScroll ist recyclerview

012.351.

und

Layoutmanager ist die Layout

recyclerview gesetzt