title: Android + How to add vertical "Auto-Scroll" feature to ScrollView or TextView
body: <p>I'm making a document reader app and I want a user to be able to ask the app the auto-scroll a document instead of the manual scrolling. Please could anyone give me ideas on how to make a ScrollView "Auto-Scroll" vertically? Sort of like credits at the end of a movie. I set up a TimerTask to this below but my problems are:</p>
  
  <ol>
  <li><p>How do I get the increment value to feed into the TimerTask i.e the new position the scrollbar should go to each time the TimerTask is run.</p></li>
  <li><p>Are there any better ways to achieve this auto-scroll feature? </p></li>
  </ol>
  
  <p>My code is below, I achieved the auto-scroll but the scrolling wasn't even...(totally new to both Java and Android..smile)...thanks!!!</p>
  
  <pre><code>Timer scrollTimer = new Timer();
  Handler handler = new Handler();
  ScrollView scrollView = (ScrollView) findViewById(R.id.hse);
  int scrollSpeed = 5; // this is set by the user in preferences
  
  TimerTask scrollerSchedule = new TimerTask() {
          @Override
          public void run() {
  
              handler.post(new Runnable() {
  
                  @Override
                  public void run() {
                      //Here I want to increment the scrollbar's vertical  position by 10
          //scrollView.smoothScrollBy(0, scrollView.getScrollY() + 10);
                                       new moveScrollView().execute();
                  }
              });
          }
      };
  
      scrollTimer.schedule(scrollerSchedule, 0, scrollSpeed * 100);
  
  }
  
  private class moveScrollView extends AsyncTask&lt;Void, Void, Void&gt; {
  
      protected void onProgressUpdate(Void... progress) {
          // show the user some sort of progress indicator
          // like how many minutes before scroll is completed
  
      }
  
      protected Void doInBackground(Void... params) {
          // TODO
          int scrollPos = (int) (scrollView.getScrollY() + 10.0);
          scrollView.smoothScrollTo(0, scrollPos);
          return null;
      }
  
  }
  </code></pre>
  
  <p>Changes: Like @Kurtis suggested, I added the AsyncTask to carry out the scroll, and then used the TimerTask + Handler to do the repetition. Now when run the scroll code</p>
  
  <pre><code>int scrollPos = (int) (scrollView.getScrollY() + 10.0);
  scrollView.smoothScrollTo(0, scrollPos);
  </code></pre>
  
  <p>in the AsynTask, I get an error, but when I run the code directly in my Runnable it works as expected. I'm still concerned about efficiency and would really want to use the AsynTask. Any tips on fixing my AsyncTask code?</p>
  
  <hr>
  
  <p>BTW: This was my observation (for newbies like me). Previously I used </p>
  
  <pre><code>scrollView.smoothScrollBy(0, scrollView.getScrollY() + 10);
  </code></pre>
  
  <p>and the scroll start jumping unevenly, sort of incrementing the scroll value like +5, +10 +15 +.... instead of an even repetition like +5, +5, +5.... What I found out was that if I wanted to compute the incremental value like scrollView.getScrollY() + 10, then I should have used smoothScrollTo() instead of smoothScrollBy().</p>
  
  <pre><code>scrollView.smoothScrollTo(0, scrollView.getScrollY() + 10);
  </code></pre>