如何知道 TextView 是否在动画中?

How to know if a TextView is in animation or not?

在 onClickListener 上,我在 textView(图标)上开始动画

Animation anim = AnimationUtils
          .loadAnimation(activity.getBaseContext(), R.anim.rotate_refresh);
icon.startAnimation(anim);

再次点击时,我想检查一下,如果图标在动画(旋转),请保持该状态,否则再次启动动画。

我想知道如何检查动画中的textview?

也许试试这样的东西

Animation animation = icon.getAnimation();
if(animation != null && animation.hasStarted() && !animation.hasEnded()){
    //do what you need to do if animating
}
else{
    //start animation again
}

它很可能会如你所愿地为你工作。

boolean isInBetweenAnim = false;
anim.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {
        isInBetweenAnim = true;
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        isInBetweenAnim = false;
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

因此,无论何时开始动画,您都将 isInBetweenAnim 设置为 true,其余时间设置为 false。轻松检查按钮 onClickisInBetweenAnim 的值,您可以为其编写代码。

希望有用!快乐编码..

这一行会让你知道 TextView 是否有动画

Animation animation=textView.getAnimation();

如果你有多个视图可以在一个视图上启动动画,你必须专注于动画视图,而不是动画。

我有多个信息图像视图,它们在文本视图中显示帮助文本。为了避免在textView上出现多个动画,我使用了Arun的方法:

    if (helpTextView.getAnimation() == null) {
        helpTextView.startAnimation(helpAnimation);
    }