旋转动画速度

发布于 2024-11-30 15:26:28 字数 577 浏览 7 评论 0原文

我希望我的动画只旋转一圈。每次我调整持续时间时,它都会以相同的速度旋转更长/更慢。我哪里错了?

私有静态最终浮点数 ROTATE_FROM = 0.0f;
私有静态最终浮点数 ROTATE_TO = -10.0f * 360.0f;
protected RotateAnimation r = new RotateAnimation(ROTATE_FROM, ROTATE_TO,
                                        动画.RELATIVE_TO_SELF, 0.5f,
                                        动画.RELATIVE_TO_SELF, 0.5f);
r.setDuration(5000);     
r.setRepeatCount(0);
r.setInterpolator(this, android.R.anim.linear_interpolator);
r.setAnimationListener(AndroidVideoPlayer.this);        
favicon.startAnimation(r);

I want my animation to only spin for one rotation. Everytime I adjust the duration it just spins at the same speed for longer/slower. Where am I going wrong?

private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = -10.0f * 360.0f;
protected RotateAnimation r = new RotateAnimation(ROTATE_FROM, ROTATE_TO,
                                        Animation.RELATIVE_TO_SELF, 0.5f,
                                        Animation.RELATIVE_TO_SELF, 0.5f);
r.setDuration(5000);     
r.setRepeatCount(0);
r.setInterpolator(this, android.R.anim.linear_interpolator);
r.setAnimationListener(AndroidVideoPlayer.this);        
favicon.startAnimation(r);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糯酥胸 2024-12-07 15:26:28

我相信您正在寻找的是 repeatCount

r.setRepeatCount(0)

http://developer.android.com/reference/android/view/animation/Animation.html#setRepeatCount(int)

从文档中:

设置动画应重复的次数。如果重复
count 为 0,动画不再重复。如果重复次数为
大于0或INFINITE,将采用重复模式
帐户。重复次数默认为0。

或者您是说动画会继续旋转您设置的任何持续时间? (即,您将其设置为 5000,即使它超过“结束”,它也会旋转 5 秒)。如果将该值设置为小于旋转动画所需的时间会怎样?

在这种情况下,可能是您的 LinearInterpolator 正在以恒定的变化率进行动画处理。您可以打印computeDurationHint()的值来查看应用程序是否能够猜测持续时间应该有多长。

PS 您的 ROTATE_FROMROTATE_TO 值是多少?

I believe what you are looking for is repeatCount

r.setRepeatCount(0)

http://developer.android.com/reference/android/view/animation/Animation.html#setRepeatCount(int)

From the documentation:

Sets how many times the animation should be repeated. If the repeat
count is 0, the animation is never repeated. If the repeat count is
greater than 0 or INFINITE, the repeat mode will be taken into
account. The repeat count is 0 by default.

Or are you saying that the animation continues to rotate for whatever duration you set? (i.e., you set it for 5000 it rotates for 5 seconds even if it overshoots the "end"). What if you set that value to less than the amount of time it takes to rotate your animation?

In that case it's probably your LinearInterpolator that's animating for a constant rate of change. You could maybe print the value of computeDurationHint() to see if the application is able to guess how long the duration should be.

P.S. What are your ROTATE_FROM and ROTATE_TO values?

鹤仙姿 2024-12-07 15:26:28

问题出在 -10.0f 上!

It was the -10.0f that was the problem!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文