滚动型自动滚动 [英] ScrollView autoscrolling

查看:160
本文介绍了滚动型自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

都让我借口这个问题:首先,我知道很多人问在这里,但我愚蠢,没有发现任何正确的答案对我来说。我有一个滚动型和许多TextViews和ImageViews它里面。我想滚动屏幕上所有的东西就像一部电影的学分。我发现这个方法。它的工作原理,但只有几秒钟,然后停止:

 公共无效scrollRight(最终滚动型高){
    新CountDownTimer(2000年,1){        公共无效onTick(长millisUntilFinished){
            h.scrollTo(0,(INT)(2000-millisUntilFinished)/ 25);        }        公共无效onFinish(){        }
     }。开始(); }


解决方案

您可以使用滚动条来创建滚动的流畅的动画效果。
这里有一个例子:
安卓滚轮动画

基本上,所有你需要做的是从0开始的滚动到列表的末尾,并调用与滚动值列表的scrollTo。

另一个选择是创建一个调用scrollBy每次定时器。

编辑:另外,您创建CountDownTimer的方式使其为2000毫秒运行,并调用onTick每1ms。如果你希望它运行的时间更长,只是增加的总时间。我也建议使用一个更大的区间 - 1ms的是太经常进行显示。试试这个:

 新CountDownTimer(10000,25){
     公共无效onTick(长millisUntilFinished){
     h.scrollBy(1,0);
}

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

解决方案

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

这篇关于滚动型自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆