动画结束后我该怎么做?
我有一个 ImageView
,用于通过 AnimationDrawable
显示进度。当我想显示进度微调器时,我这样做:
animDrawable.start();
ObjectAnimator.ofFloat(view, "alpha", 1.0f).setDuration(300).start();
当我想隐藏微调器时,我这样做:
ObjectAnimator.ofFloat(view, "alpha", 0.0f).setDuration(300).start();
animDrawable.stop();
但是,这会产生动画立即停止的效果。我希望它仅在 ObjectAnimator
完全褪色到 0.0 alpha 后停止。有没有办法可以按照“AnimationCompleted”回调来设置某些内容?
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();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更现代的方法是使用
ViewPropertyAnimator
:或者,如果您使用的是 RetroLambda:
The more modern way of doing this is to use the
ViewPropertyAnimator
:Or, if you're using RetroLambda:
对于有关 ObjectAnimator 对象的原始问题,您可以设置一个 Animator.AnimatorListener 对象,该对象定义多个动画状态回调。您想要覆盖 public void onAnimationEnd(Animator Animation)
To your original question about the ObjectAnimator object you can set up an Animator.AnimatorListener object which defines several animation state callbacks. You want to override public void onAnimationEnd(Animator animation)
使用 androidx,您可以使用 doOnEnd 方法,该方法在动画结束时调用
With androidx you can use doOnEnd method which invoked when the animation has ended
您还可以查看 postOnAnimation(Runnable)
文档链接: postOnAnimation(java.lang.Runnable)
You could also look into postOnAnimation(Runnable)
Link to Docs: postOnAnimation(java.lang.Runnable)
您可以将此代码与 Kotlin 上的对象动画器一起使用
You can use this code with Object animator on Kotlin