我该怎么做,当一个动画完成的东西吗? [英] How do I do something when an animation finishes?

查看:131
本文介绍了我该怎么做,当一个动画完成的东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ImageView ,我用它来显示通过一个进度 AnimationDrawable 。当我想告诉我的进步微调,我这样做:

I have an ImageView that I use to show progress via an AnimationDrawable. When I want to show my progress spinner, I do this:

animDrawable.start();
ObjectAnimator.ofFloat(view, "alpha", 1.0f).setDuration(300).start();

当我想隐藏的微调,我这样做:

When I want to hide the spinner, I do this:

ObjectAnimator.ofFloat(view, "alpha", 0.0f).setDuration(300).start();
animDrawable.stop();

然而,这具有这样的动画立即停止的效果。我想它停止后,才 ObjectAnimator 已完全褪去0.0阿尔法。有没有一种方法,我可以设置沿着一个AnimationCompleted回调线的东西?

However, this has the effect that the animation stops immediately. I would like it to stop only after the ObjectAnimator has completely faded to 0.0 alpha. Is there a way I can setup something along the lines of an "AnimationCompleted" callback?

推荐答案

看起来像<一个href="http://developer.android.com/reference/android/animation/Animator.html#addListener%28android.animation.Animator.AnimatorListener%29">base类有一个监听。

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
anim.addListener(new AnimatorListener() {
    ...
    @Override 
    public void onAnimationEnd(Animator animation) {
        animDrawable.stop()            
    }
    ...
});
anim.setDuration(300).start();

这篇关于我该怎么做,当一个动画完成的东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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