动画结束后我该怎么做? [英] How do I do something when an animation finishes?
问题描述
我有一个 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 alpha 后停止.有没有办法可以按照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?
推荐答案
更现代的方法是使用 ViewPropertyAnimator
:
The more modern way of doing this is to use the ViewPropertyAnimator
:
view.animate()
.alpha(0f)
.withEndAction(new Runnable() {
@Override
public void run() {
// Do something.
}
})
.start();
或者,如果您使用的是 RetroLambda:
Or, if you're using RetroLambda:
view.animate()
.alpha(0f)
.withEndAction(() -> {
// Do something.
})
.start();
这篇关于动画结束后我该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!