-2

First of all let me excuse for this question, I know that many other people asked it here, but I am so stupid that did not find any correct answer for me. I have a ScrollView and many TextViews and ImageViews inside of it. I want to scroll all this stuff across the screen like a movie's credits. I found this method. It works but only for a few seconds and then stops.:

            public void scrollRight(final ScrollView h){
    new CountDownTimer(2000, 1) { 

        public void onTick(long millisUntilFinished) { 
            h.scrollTo(0,(int) (2000-millisUntilFinished)/25);

        } 

        public void onFinish() { 

        } 
     }.start(); }
Onigrey
  • 13
  • 2
  • 4

2 Answers2

1

you can use a scroller to create a smooth animation of the scroll. there's an example here: Android: Scroller Animation?

basically, all you need to do is start the scroller from 0 to the end of the list and call the scrollTo of the list with the scroller value.

another option is to create a timer that calls scrollBy every time.

EDIT: also, the way you created CountDownTimer causes it to run for 2000 milliseconds, and call onTick every 1ms. If you want it to run longer, just increase the overall time. I also suggest using a bigger interval - 1ms is way too often for display purposes. Try this:

new CountDownTimer(10000, 25) { 
     public void onTick(long millisUntilFinished) { 
     h.scrollBy(1,0);
}
Community
  • 1
  • 1
iagranat
  • 93
  • 6
0

You can also use ObjectAnimator to achieve this:

ObjectAnimator.ofInt(view, "scrollY", 0, view.getBottom).setDuration(1000).start;

Micer
  • 8,731
  • 3
  • 79
  • 73