Search code examples
androidanimationanimator

How to add delay between animations


I'm having a trouble with animations in android. I have my animation_char.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
    android:duration="300"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0"/>
</set>

That is ok, but in my MainActivity I want to start an animation one after one. So I created a method to make it more easy and just change the ImageView

public void animation(ImageView imageView){
    animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.animation_char);
    imageView.startAnimation(animation);
}

And for make consecutives animations, I'm trying to use AnimatorSet. But as I read AnimatorSet works with Animator, not with Animation. So my question is: is there a way to load an animation in a animator?? Or should I use another way in order to achieve what I want to do? Thanks in advance!

EDIT I changed my method and now Im trying with this but the problem is that all the images appear at the same time, how can I add some delay between animations?

public void animation() {
    animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.animation_char);

            w.startAnimation(animation);
            a.startAnimation(animation);
            r.startAnimation(animation);     
}

Solution

  • Actually I've answered on this question here. You should start your second animation in onAnimationEnd of AnimationListener of first animations. The same for second one.