Android撤销 View 动画

标签 android

我使用以下代码旋转一个名为 photoImageView:

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,90,400)。之后,要“撤消”动画,我可以使用 rotatePhoto(0,0,0)

关于Android撤销 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32575218/

相关文章:

Android - 蓝牙 - 限制扫描范围

java - APP停止工作 - fragment

android - 如何监控应用程序的扩展?

android - 在 GridView 中拖放项目

java - Android 无法更新 ArrayAdapter,因为 "Non-Static method ' notifyDataSetChanged( )' cannot be referenced from a static context"

c# - 无法通过 Unity 将数据写入 Firebase 数据库

java - 如何在方法之间正确传递上下文以使用数据库存储库?

android - 从任务管理器中删除应用程序时调用哪个函数

android - 确保释放 OpenGL 纹理内存

android - 在android中动态添加标签