如何改变startScroll的速度() [英] How to change velocity of startScroll()
问题描述
我使用这回答来实现跑马灯的TextView
在我的应用程序,但我希望能够改变它的速度,而无需设置滚轮
的持续时间。
如果我设置了滚轮
的持续时间,则文本的速度将取决于有多少文字,但我想要的是速度恒定。
有没有办法做到这一点?
如果没有,是否有任何其他方式使文字在一定速度自动滚动?
I'm using this answer to implement a marquee textView
in my app, but I want to be able to change the velocity of it without having to set a duration of the Scroller
.
If I set a duration for the Scroller
, then the velocity of the text will be dependent on how much text there is, but what I want is for the velocity to be constant.
Is there any way to do this?
If not, is there any other way to make text automatically scroll at a certain velocity?
推荐答案
您误解code。
您必须设置为滚动的持续时间,否则怎么会就知道多少时间服用。
You have to set a duration for the scroller otherwise how would it know how much time to take.
所以,现在我们必须做出不断滚动的速度。
So now we have to make the velocity of the scroller constant.
但 =速度距离/时间
因此,为了使该常数的方式是使持续时间距离的函数
So the way to make that constant is to make the duration a function of distance
有关如。如果时间= 2 *距离
速度= 2
等。
从code你已经发布
int distance = scrollingLen - (getWidth() + mXPaused);
int duration = (new Double(mRndDuration * distance * 1.00000
/ scrollingLen)).intValue();
现在持续时间=距离*常数/ scrollingLen
所以才删除 scrollingLen
键,这将是距离的纯函数给你等速
So just remove the scrollingLen
and it'll be a pure function of distance giving you constant velocity
duration= distance * constant /anotherConstant
这篇关于如何改变startScroll的速度()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!