Malleswar Chinta
Malleswar Chinta

Reputation: 168

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

upon onClickListener, I am starting an animation on textView (icon)

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

on clicking again, I want to check, if the icon is animating (rotating) , keep it that way or else start the animation again.

I want to know how can I check textview is in animation?

Upvotes: 6

Views: 2668

Answers (4)

Kuvalya
Kuvalya

Reputation: 1094

If you have multiple views that can start an animation on one view , you must focus on animated view, not animation.

I had multiple info imageViews that shows help text in a textView. To avoid multiple animations on textView, I used Arun's approach:

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

Upvotes: 0

Arun PS
Arun PS

Reputation: 4650

This line will let you know if the TextView is animated

Animation animation=textView.getAnimation();

Upvotes: 6

user1460340
user1460340

Reputation:

It will most probably work for you as you want to do.

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) {

    }
});

So whenever a animation starts you will have isInBetweenAnim true and for rest you will have it false. Easily check the value of isInBetweenAnim in onClick of your button and you can code for it.

Hope it Works ! Happy Coding..

Upvotes: 0

MikeIsrael
MikeIsrael

Reputation: 2889

Maybe try something like this

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

Upvotes: 9

Related Questions