我的图像旋转了36°。 我使用了setFillAfter()和setFillEnabled()。它保存了位置,但是如果我再次旋转它,它将从原始位置开始。我希望它从旋转后的位置开始。
Animation animation = new Animation (0,36, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);
animation.setInterpolator(new LinearInterpolator());
animation.setFillAfter(true);
myImage.startAnimation(animation);
答案 0 :(得分:0)
您只需要在动画构造函数中传递imageview的当前角度,而不是每次都传递0。请尝试以下代码:
int rotationAngle=36;/*angle by which you want to rotate image*/
int mCurrRotation = 0; /*current angle of image*/
buttonRotate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
float fromRotation = mCurrRotation;
float toRotation = mCurrRotation += rotationAngle;
Animation animation = new RotateAnimation(
fromRotation,
toRotation,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(3000);
animation.setFillAfter(true);
myImage.startAnimation(animation);
}
});
答案 1 :(得分:0)
执行旋转后,将图像的x坐标设置为旋转的新位置...