我想以这种方式对imageView进行动画处理:(按三角学定义的角度符号)
使用下面的代码,我得到:
所以,根本不是我想要的!
有人看到如何解决这个问题?
谢谢!
这是我的代码:
float angle = 45f;
RotateAnimation rotateAnimation1 = new RotateAnimation(0, -angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setStartOffset(0);
rotateAnimation1.setDuration(2000);
rotateAnimation1.setInterpolator(new LinearInterpolator());
RotateAnimation rotateAnimation2 = new RotateAnimation(-angle, angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// animationSet.addAnimation(rotateAnimation);
rotateAnimation2.setStartOffset(0);
rotateAnimation2.setDuration(4000);
rotateAnimation2.setInterpolator(new LinearInterpolator());
RotateAnimation rotateAnimation3 = new RotateAnimation(angle, -angle,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation3.setStartOffset(4000);
rotateAnimation3.setDuration(4000);
rotateAnimation3.setInterpolator(new LinearInterpolator());
final AnimationSet animSet1 = new AnimationSet(true);
animSet1.setFillEnabled(true);
animSet1.addAnimation(rotateAnimation1);
final AnimationSet animSet2 = new AnimationSet(true);
// animSet2.setFillEnabled(true);
animSet2.addAnimation(rotateAnimation2);
animSet2.addAnimation(rotateAnimation3);
animSet1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(animSet2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animSet2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.startAnimation(animSet2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(animSet1);
答案 0 :(得分:0)
视图返回零的原因是视图的旋转属性未更改。您应该在第一个动画结束后将旋转设置为打开视图,或使用ObjectAnimator.ofFloat(imageview ,"rotation", 0f, 360f);
来默认设置视图的旋转。
答案 1 :(得分:0)
1。从0到-45平滑旋转:反转角度符号和setFillAfter(true)
,以便视图保持动画位置结束
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 45f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setFillAfter(true); //This keeps view at animation ended position
rotateAnimation1.setStartOffset(0);
rotateAnimation1.setDuration(2000);
rotateAnimation1.setInterpolator(new LinearInterpolator());
2。从-45平滑旋转到+45::将动画的起始角度设置为0,因为视图已经旋转。
// Since view already is at -45 position due to rotateAnimation1.setFillAfter(true), now start point is 0 again
RotateAnimation rotateAnimation2 = new RotateAnimation(0, -90,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation2.setFillAfter(true);
rotateAnimation2.setStartOffset(0);
rotateAnimation2.setDuration(4000);
rotateAnimation2.setInterpolator(new LinearInterpolator());
按照上面的逻辑,其余步骤很简单。