Android的:如何停止施用在ImageView的无限动画? [英] Android: How can I stop an infinite animation applied on an ImageView?

查看:2970
本文介绍了Android的:如何停止施用在ImageView的无限动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于这一点我已经应用了旋转动画的ImageView的。因为我想旋转持续下去的话,我给的repeatCount是无限的在我的rotate.xml:

I have an ImageView on which I have applied a rotate animation. Since I want the rotation to go on continuously, I gave the repeatCount as infinite in my rotate.xml:

android:repeatCount="infinite"

在的onCreate(),我加载动画,并启动它。

In onCreate(), I load the animation and start it.

Animation myAnim    = AnimationUtils.loadAnimation(this, R.anim.rotate);
objectImg.startAnimation(myAnim); 

当一个按钮pssed $ P $,旋转必须停止。因此,在我的onClick(),我叫clearAnimation()。

When a button is pressed, the rotation must stop. Hence in my onClick(), I called clearAnimation().

objectImg.startAnimation(myAnim); 

我的简单的问题是,是否停止动画是正确的事情。 我假定clearAnimation()对应loadAnimation(),但也有是对应于startAnimation()。

My simple question is whether stopping the animation is the right thing to do. I assume clearAnimation() corresponds to loadAnimation(), but there is no stopAnimation() that corresponds to startAnimation().

推荐答案

您也可以拨打 anim.cancel(); 但你也应该叫 anim.reset(); 紧随其后。 然后,当你想再次启动它,只需拨打 startAnimation 的看法。

You can also call anim.cancel(); but you should also call anim.reset(); immediately after it. Then when you want to start it again, just call startAnimation on the view.

这篇关于Android的:如何停止施用在ImageView的无限动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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