如何使用AnimationDrawable我暂停帧动画? [英] How do i pause frame animation using AnimationDrawable?

查看:189
本文介绍了如何使用AnimationDrawable我暂停帧动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用AnimationDrawable我暂停帧动画?

How do i pause frame animation using AnimationDrawable?

推荐答案

我知道这个线程是很老,但因为这是当我正在寻找一种方法来暂停动画在谷歌的第一个答案,我就在这里发布的解决方案,为别人看到。 你需要做的是继承动画类型,你想使用,然后添加的方法暂停和恢复动画。下面是AlphaAnimation一个例子:

I realize this thread is quite old, but since this was the first answer on Google when I was searching for a way to pause an animation, I'll just post the solution here for someone else to see. What you need to do is subclass the animation type you'd like to use and then add methods for pausing and resuming the animation. Here is an example for AlphaAnimation:

public class PausableAlphaAnimation extends AlphaAnimation {

    private long mElapsedAtPause=0;
    private boolean mPaused=false;

    public PausableAlphaAnimation(float fromAlpha, float toAlpha) {
        super(fromAlpha, toAlpha);
    }

    @Override
    public boolean getTransformation(long currentTime, Transformation outTransformation) { 
        if(mPaused && mElapsedAtPause==0) {
            mElapsedAtPause=currentTime-getStartTime();
        }
        if(mPaused)
            setStartTime(currentTime-mElapsedAtPause);
        return super.getTransformation(currentTime, outTransformation);
    }

    public void pause() {
        mElapsedAtPause=0;
        mPaused=true;
    }

    public void resume() {
        mPaused=false;
    }
}

这将不断增加你的开始时间,而动画暂停时,从整理和保持有效保持它的它的状态,当你停下它。

This will keep increasing your starttime while the animation is paused, effectively keeping it from finishing and keeping it's state where it was when you paused.

希望它可以帮助别人。

这篇关于如何使用AnimationDrawable我暂停帧动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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