我已经为两个图像创建了两个动画并且它工作正常但我希望在第一个动画完成时启动第二个动画。
代码:
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);
}
}
这是第一个动画片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>
这是第二个动画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>
答案 0 :(得分:5)
你可以这样做&amp;这对我有用。
只需在活动
中实施AnimationListener
即可
public class animation001 extends Activity implements AnimationListener {
.........
}
按照此tutorial,这有助于您更好地实施动画。
答案 1 :(得分:1)
AnimationListener
并实施public void onAnimationEnd(Animation animation)
。AnimationListener
Animation.setAnimationListener()
设置为您的第一个动画
AnimationListener.onAnimationEnd()