title: RecyclerView continuous loop automatic smoth Scrolling
body: <p><strong>Background:</strong>
  I'm developing a tournament management software and I want to show the current contenders classification on a screen that is feed by an android device.
  The number of contenders exceeds the vertical size of the screen, so I would like to show it using a nice vertical animate smoth scroll from bottom to top that would be endless (when the list shows the last element it would start showing the first as it would be a loop.</p>
  
  <p><strong>Approach:</strong>
  After some research (sorry I don't have the all the references) I come up with the following implementation:
  I'm using a recyclerview with an adapter on a fragment. In order to automatically scroll it up I have added a timer that would scroll the recycleview on fixed itervals:</p>
  
  <pre><code>CountUpTimer recyclerViewAutoScroll =  new CountUpTimer(1) {
      public void onTick(long millis) {
          recyclerView.scrollBy(0, mSpeed * 2);
          if (!recyclerView.canScrollVertically(1)) {
              recyclerView.scrollToPosition(0);
          }
      }
  };
  </code></pre>
  
  <p>This timer is being created and launched on a global layout listener:</p>
  
  <pre><code>@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
      layoutListener = () -&gt; {                          
               recyclerView.post(() -&gt; recyclerViewAutoScroll.start());
  recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
  }
  </code></pre>
  
  <p>The CountUpTimer class is just an "infinite" timer implemented using an android CountDowntimer.</p>
  
  <p>With this piece of code I can scroll up at regular times, the problem is that is not smoth at all. There are two parameters to play with: the timer tick time, and the amount of vertical scroll that is made each time the timer "ticks". The only way to make it "smooth" is to reducing so much the scroll movement that it ended being very very very slow for the user.</p>
  
  <p>Just for completeness, to achieve the endless scroll efect I added an scroll listener to the recycler view:</p>
  
  <pre><code>recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(5) {
                   @Override
                   public void onLoadMore(int currentPage) {
                       Timber.d("new Page " + currentPage);
                       recyclerView.post(() -&gt;
                       {
                           itemAdapter.addModel(currentClassificationList);
                           if (currentPage &gt; 2)
                               itemAdapter.removeModelRange(0, currentClassificationList.size());
                       });
                   }
  </code></pre>
  
  <p>What I do there is just add twice the classificationList to have enough space on the bottom to show the top of the list after the last element, and I keep adding the list to the bottom and removing from the top every time the recyclerview is about to reach the end of the list.</p>
  
  <p>So my question is: How can I implement a really smoth scroll animation of the recyclerview? As I said this is being shown WITHOUT any user interaction, just on a screen where the classification is continuously being shown and scrolled.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After one comment suggestion I substituted the count timer by a TimeAnimator class this way:</p>
  
  <pre><code>timeAnimator.setTimeListener(new TimeAnimator.TimeListener() {
          @Override
          public void onTimeUpdate(TimeAnimator timeAnimator, long l, long l1) {
              Timber.d("elapsed: " + l1);
              recyclerView.scrollBy(0, (int)(l1/ mSpeed));
              if (!recyclerView.canScrollVertically(1)) {
                  recyclerView.scrollToPosition(0);
              }
          }
      });
  </code></pre>
  
  <p>Also I removed the post calls as they are not needed.
  Now the smoothness has improved, but is not perfect, it still hessitate a bit when a new item is about to appear from the bottom.
  I'm looking now to the itemadapter to improve any calculation made there and any image loading (I added Picasso for image loading also) But still it is not perfect, they are some flickering there.</p>