0

我正在尝试一个非常简单的动画。将视图向左旋转 18°,然后向右旋转 180°(相对)(+162°绝对),然后返回正常 0°(绝对)(-162°相对)...

int first = -18;
int second = first +180;
int animationGap = 500;
//left rotation
final RotateAnimation leftRotation = new RotateAnimation(0, first, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
leftRotation.setDuration(1000);
leftRotation.setInterpolator(new AccelerateDecelerateInterpolator());
//right rotation
final RotateAnimation rightRotation = new RotateAnimation(first, second, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rightRotation.setDuration(1000);
rightRotation.setStartOffset(1000+animationGap);
rightRotation.setInterpolator(new AccelerateDecelerateInterpolator());
//back to normal rotation
final RotateAnimation toNormalRotation = new RotateAnimation(second, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
toNormalRotation.setDuration(1000);
toNormalRotation.setStartOffset(2000+animationGap*2);
toNormalRotation.setInterpolator(new AccelerateDecelerateInterpolator());
//animation set
final AnimationSet animationSet = new AnimationSet(true);
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.addAnimation(leftRotation);
animationSet.addAnimation(rightRotation);
animationSet.addAnimation(toNormalRotation);

我从这个开始整个捆绑:

view.startAnimation(animationSet);

它按预期工作,first= -90;但上星座完全错误......(在三星s4和谷歌nexus s上测试)
当然我可以快速解决这个问题AnimationListener并从中开始下一个动画,但这不是真正的解决方案或答案.
那么有没有人可以告诉我为什么会发生这种情况以及如何防止这种情况发生?
编辑:
我认为问题可能是作为矩阵的底层数学表示(旋转可能会操纵每个 otehr)。但这应该不是问题,因为android可以识别这一点,或者由于两者之间的时间延迟可能会产生不同的问题。
我仍在寻找一个不错的解决方案

4

1 回答 1

0

我的猜测是正确的,所以唯一的解决方案是使用AnimationListener每一个旋转并在 onEnd 方法中开始下一个旋转..

于 2014-03-06T10:21:44.927 回答