Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

android - ScrollView autoscrolling

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(); }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...