Search code examples
androidscrollscrollview

Scroll up a ScrollView slowly


The question is "How do i scroll up a ScrollView to top very smoothly and slowly".

In my special case i need to scroll to top in about 1-2 seconds. Ive tried interpolating manually using a Handler (calling scrollTo(0, y)) but that didnt work at all.

I've seen this effect on some bookreader-apps yet, so there must be a way, im sure :D. (Text is very slowly scrolling up to go on reading without touching the screen, doing input).


Solution

  • In 2 seconds move the scroll view to the possition of 2000

    new CountDownTimer(2000, 20) {          
    
     public void onTick(long millisUntilFinished) {     
       scrollView.scrollTo(0, (int) (2000 - millisUntilFinished)); // from zero to 2000    
     }          
    
     public void onFinish() {  
     }      
    
    }.start();