如何在固定的时间内运行imageview动画(重复无限,持续时间不可更改)?

时间:2013-09-16 23:08:02

标签: java android animation imageview rotateanimation

我在imageview对象上运行了RotateAnimation。

此动画使对象每次旋转的速度为(myAnimation.setDuration(x))。

我有很多以不同速率旋转的对象和动画,所有对象都设置为repeatCount(INFINITY)。

我希望让所有人在固定的时间内完成他们的事情(即:3个旋转物体,物体1旋转5圈,物体2旋转20.33圈,物体3旋转0.4圈)。

/ e同样重要的是倒计时结束时每个物体的位置保存在某处/返回,因为我将从那些坐标开始另一个旋转动画。

另请注意,所有这些旋转都是针对每个物体自身的中心完成的,所以按坐标我的意思是度数!

有人有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我对Android很新,但我遇到了类似的问题,所以我会根据我对你想要达到的目标的理解来回答你的问题。

所以我想如果你想让你的物体旋转固定的转弯量,你不需要旋转它们进行无限计数。相反,也许您可​​以使用您喜欢的速率旋转每个对象一次所需的转弯量。因此,为了论证,您希望您的对象以每次旋转5秒的速度旋转,或者换句话说,需要5秒才能完成一次完整的360度旋转。我将使用您的问题中的示例对象3,该问题需要 0.4 转:

// define animation for 0.4 turn object
final RotateAnimation rotateObj3_part1 = new RotateAnimation(0, 360*0.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // 360*0.4 = 144 deg
rotateObj3_part1.setDuration((long) (5000*0.4)); // 5 sec for full circle, 2 sec for 0.4 of circle
rotateObj3_part1.setFillAfter(true); // this will make object stay in rotated position
rotateObj3_part1.setRepeatCount(0);

ImageView object3 = (ImageView)findViewById(R.id.object3);
object3.startAnimation(rotateObj3_part1);

现在要从先前的位置开始更多地旋转同一个对象,定义从旧的一个开始的新的RotateAnimation:

final RotateAnimation rotateObj3_part2 = new RotateAnimation(360*0.4f, newEndPoint, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); // so now rotate from 144 degrees to newEndPoint degrees
rotateObj3_part2.setDuration((long) (5000*((newEndPoint-360*0.4f))/360); // scale 5 sec to new change in degrees
rotateObj3_part2.setFillAfter(true);
rotateObj3_part2.setRepeatCount(0);
object3.startAnimation(rotateObj3_part2);

我希望这有意义,并为您提供您想要实现的结果。

相关问题