0

I have a RotateAnimation running on an imageview object.

This animation makes the object rotate at the rate of (myAnimation.setDuration(x)) per rotation.

I have quite a few of the objects and animations rotating at different rates, all objects set to repeatCount(INFINITY).

I want to be make all of them do their thing for a fixed duration (ie: 3 rotating objects, object 1 does 5 turns, object 2 does 20.33 turns, and object 3 does 0.4 turns).

/e It is also important that the position of each object at the end of the countdown is saved somewhere/returned, as I will start another rotate animation from those coordinates.

Also note, all these rotations are done about each object's own center, so by coordinates I mean degrees!

Anyone have any ideas?

Thanks!

4

1 回答 1

0

我对android还很陌生,但我遇到了类似的问题,所以我将尝试根据我对您想要实现的目标的理解来回答您的问题。

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

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

我希望这是有道理的,并能让你得到你想要达到的结果。

于 2013-09-17T08:54:22.223 回答