Android撤消视图动画

Android撤消视图动画,android,Android,我正在使用以下代码旋转一个名为photo的ImageView: RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(400); rotate.setFillEnabled(true); rotate.setFill

我正在使用以下代码旋转一个名为
photo
ImageView

RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(400);
    rotate.setFillEnabled(true);
    rotate.setFillAfter(true);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setAnimationListener(new Animation.AnimationListener() {
    });
    photo.startAnimation(rotate);

它很好地旋转并持续。稍后我可能想更改此ImageView中的图片。但是,由于上一幅图像上的持久动画,我的新图像显示为旋转。如何在切换图像之前“撤消”此动画?

显然,最好的方法是使用另一个零持续时间的动画。如果此函数中有我的原始动画:

private void rotatePhoto(int fromDegrees, int toDegrees, int duration) {
    RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(duration);
    rotate.setFillEnabled(true);
    rotate.setFillAfter(true);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setAnimationListener(new Animation.AnimationListener() {
    });
    photo.startAnimation(rotate);
}

我可以像这样将照片旋转90度:
rotatePhoto(0,90400)
。之后,要“撤消”动画,我可以使用
rotatePhoto(0,0,0)

也许这会对您有所帮助:尝试制作反向动画,如果您不想动画,可能会将持续时间设置为0…stopAnimation()不起作用?stopAnimation()不会起作用,因为动画很早以前就完成了。到目前为止,唯一可行的解决方案是创建一个持续时间为0的反向动画,但我不确定这是否是最好的解决方案。。。