【问题标题】:Android undo view animationAndroid撤消视图动画
【发布时间】:2015-09-20 15:24:39
【问题描述】:

我正在使用此代码旋转一个名为 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 中的图片。但是,由于前一个图像上的持续动画,我的新图像出现旋转。如何在切换图像之前“撤消”此动画?

【问题讨论】:

  • 也许这会对你有所帮助:stackoverflow.com/questions/4120824/…
  • 尝试做反向动画,如果你不想让它动画,也许将持续时间设置为 0...
  • stopAnimation() 不工作?
  • stopAnimation() 无法正常工作,因为动画在很久以前就完成了。到目前为止,唯一可行的解​​决方案是创建一个持续时间为 0 的反向动画,但我不确定这是否是最好的解决方案......

标签: android


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-19
    • 2017-08-19
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    相关资源
    最近更新 更多