0

I have an imageview which has two animations: when the first finishes, the second started. First it goes down and then up. The problem is that, when the image ends the first animation, immediately returns for an istant to the initial position and then starts the second animation.

Here is the xml animations code:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<set
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromYDelta="0"
        android:toYDelta="10"
        android:duration="300">
    </translate>
</set>

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
<set
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromYDelta="10"
        android:toYDelta="0"
        android:duration="300">
    </translate>
</set>

Here is the activity animation code:

public void startFirstAnimation()
{
    Animation set  = AnimationUtils.loadAnimation(this,R.anim.animazione1);
    immagineNemico.setAnimation(set);
    set.setAnimationListener(new Animation.AnimationListener()
    {
        @Override
        public void onAnimationStart(Animation animation)
        {

        }

        @Override
        public void onAnimationEnd(Animation animation)
        {
            startSecondAnimation();
        }

        @Override
        public void onAnimationRepeat(Animation animation)
        {

        }
    });
}


public void startSecondAnimation()
{
    Animation set  = AnimationUtils.loadAnimation(this,R.anim.animazione2);
    immagineNemico.setAnimation(set);
    set.setAnimationListener(new Animation.AnimationListener()
    {
        @Override
        public void onAnimationStart(Animation animation)
        {

        }

        @Override
        public void onAnimationEnd(Animation animation)
        {
            startFirstAnimation();
        }

        @Override
        public void onAnimationRepeat(Animation animation)
        {

        }
    });
}
Curio
  • 1,331
  • 2
  • 14
  • 34

0 Answers0