如何在第一个动画结束后开始第二个动画

Moh*_*mar 0 java xml animation android

我为两个图像创建了两个动画,它工作正常,但我希望第一个动画完成时第二个动画开始.

代码:

package com.example.animatest;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class animation001 extends Activity {

    private ImageView image1;
    private ImageView image2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image1 = (ImageView) findViewById(R.id.imageView1);
        image2 = (ImageView) findViewById(R.id.imageView2);

        final Animation animTranslate1 = AnimationUtils.loadAnimation(this,
                R.anim.translate);
        final Animation animTranslate2 = AnimationUtils.loadAnimation(this,
                R.anim.translate2);

        image1.startAnimation(animTranslate1);
        image2.startAnimation(animTranslate2);

    }

}
Run Code Online (Sandbox Code Playgroud)

这是第一个动画xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromXDelta="-100%p"
        android:toXDelta="0"
        android:duration="1500"
        android:repeatCount="0"
        android:repeatMode="reverse" />
</set>
Run Code Online (Sandbox Code Playgroud)

这是第二个动画xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <translate
        android:fromYDelta="-100%p"
        android:toYDelta="0"
        android:duration="25000"
        android:repeatCount="0"
        android:repeatMode="reverse" />
</set>
Run Code Online (Sandbox Code Playgroud)

Dix*_*tel 5

你可以这样做,它对我有用.

只需AnimationListener在您的活动中实施

public class animation001 extends Activity implements AnimationListener {
    .........
}
Run Code Online (Sandbox Code Playgroud)

按照本教程,它可以帮助您更好地实现动画.