Reputation: 168
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
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
Reputation: 4650
This line will let you know if the TextView is animated
Animation animation=textView.getAnimation();
Upvotes: 6
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
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