Animations in sequence

I want to set colors to my tiles in sequence. This function is called in a for-loop, so its called some times in a very short timewindow.

            tile.setImage(R.drawable.blue);

This is the function:

public void setImage(int resId){

    Animation fadeInAnimation = AnimationUtils.loadAnimation(this.getContext(), R.animator.fadein);
    startAnimation(fadeInAnimation);

    setImageResource(resId);
}

and this is the fadein.xml

<alpha
    android:duration="1000"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />

</set>

I want the animation to start only if the animation before it is done. So I would like the first image to be drawn the first sec and the second image during the second sec, and so on.

BR

Answers


Use AnimationListener especially its method onAnimationEnd(Animation animation)

fadeInAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // CALL next animation
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });`

Need Your Help