反转动画 [英] Reversing an Animation

查看:28
本文介绍了反转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ImageView,当它被添加到布局时会被动画化.当它被移除时,我想反转相同的动画.

I have an ImageView that gets animated when it is added to a layout. When it is removed, I want to reverse the same animation.

有没有办法在android中反转动画而不需要重新编码和反转参数?

Is there a way to reverse an animation in android without recoding it and reversing the parameters?

推荐答案

不,遗憾的是您不能使用 Animation 对象来做到这一点.但是你可以使用一个可以反转动画的插值器来模拟它:

No, sadly you cannot do it with the Animation object. But you can simulate it using an interpolator that will inverse the animation:

package com.example.android;

import android.view.animation.Interpolator;

public class ReverseInterpolator implements Interpolator {
    @Override
    public float getInterpolation(float paramFloat) {
        return Math.abs(paramFloat -1f);
    }
}

然后在你的动画上你可以设置你的新插值器:

Then on your animation you can set your new interpolator:

myAnimation.setInterpolator(new ReverseInterpolator());

这篇关于反转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆