Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在第一个动画完成后启动第二个动画_Java_Android_Xml_Animation - Fatal编程技术网

Java 如何在第一个动画完成后启动第二个动画

Java 如何在第一个动画完成后启动第二个动画,java,android,xml,animation,Java,Android,Xml,Animation,我已经为两个图像创建了两个动画,工作正常,但我希望第二个动画在第一个动画完成后开始 守则: 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.ImageVie

我已经为两个图像创建了两个动画,工作正常,但我希望第二个动画在第一个动画完成后开始

守则:

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 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>

这是第二个动画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 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>

  • 创建一个
    AnimationListener
    ,并在animationEnd(动画)上实现
    public void
  • 使用
    animation.setAnimationListener()
  • AnimationListener.onAnimationEnd()中启动第二个动画
  • 创建一个
    AnimationListener
    ,并在animationEnd(动画)上实现
    public void
  • 使用
    animation.setAnimationListener()
  • AnimationListener.onAnimationEnd()中启动第二个动画

  • 你可以这样做&这对我很有用

    只需在您的活动中实施
    AnimationListener

    public class animation001 extends Activity implements AnimationListener {
        .........
    }
    

    遵循这一点可以帮助您更好地实现动画

    您可以这样做&这对我很有用

    只需在您的活动中实施
    AnimationListener

    public class animation001 extends Activity implements AnimationListener {
        .........
    }
    

    遵循这一点可以帮助您更好地实现动画

    查看此SO问题的公认答案:我的问题没有答案,他说他不会为您编写代码。然而,在他提供的链接中有很好的材料可以解决问题。@Mohammed Asmar让你检查我的解决方案我正在尝试,但我可以在这个问题上找到公认的答案,所以问题:我的问题没有答案,他说他不会为你写代码。然而,在他提供的链接中有很好的材料可以解决问题。@Mohammed Asmar让你检查我的解决方案我正在尝试,但我不能