Check if AnimatorSet has finished animation?
You can set an AnimatorListener on fadeinAnimation5. This will give you an onAnimationEnd callback.
fadeinAnimation5.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// ...
}
@Override
public void onAnimationRepeat(Animator animation) {
// ...
}
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
@Override
public void onAnimationCancel(Animator animation) {
// ...
}
});
Or, as suggested by slott use an AnimatorListenerAdapter
fadeinAnimation5.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
}
You can actually set a listener to the AnimatorSet directly since AnimatorSet inherits from Animator. Here's some code:
import android.animation.Animator;
AnimatorSet setQuestion = new AnimatorSet();
setQuestion.playSequentially(fadeinAnimationQ,fadeinAnimation1,fadeinAnimation2,fadeinAnimation3,fadeinAnimation4,fadeinAnimation5);
setQuestion.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
// !! turn on your onClickListener here !!
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
setQuestion.start();
I was having a similar problem and here is how I solved it:
private void crossFadeAnimation(final View fadeInTarget, final View fadeOutTarget, long duration){
AnimatorSet mAnimationSet = new AnimatorSet();
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(fadeOutTarget, View.ALPHA, 1f, 0f);
fadeOut.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
fadeOutTarget.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
fadeOut.setInterpolator(new LinearInterpolator());
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(fadeInTarget, View.ALPHA, 0f, 1f);
fadeIn.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
fadeInTarget.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
fadeIn.setInterpolator(new LinearInterpolator());
mAnimationSet.setDuration(duration);
mAnimationSet.playTogether(fadeOut, fadeIn);
mAnimationSet.start();
}