java - 如何在动画结束后开始新的 Activity ?

标签 java android animation

我对 Android 很陌生,我找不到关于如何在动画结束时启动新 Activity 的线程。

这是我的代码:

public class Intro extends Activity {

    AnimationDrawable anim = new AnimationDrawable();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);
        ImageView iv =(ImageView) findViewById(R.id.imageView1);          
        iv.setBackgroundResource(R.anim.animation);    
        anim = (AnimationDrawable) iv.getBackground(); 

        iv.post(new Runnable(){    
            public void run(){    
                anim.start();        
        }

        });

    }

}

最佳答案

据我所知,没有回调机制来确定 AnimationDrawable 何时完成迭代。你能做的就是查询帧数和每帧的延迟。总结一下并在该持续时间内延迟发布。在该回调中,您可以开始第二个 Activity 。

请注意,按照您的方式启动动画有点危险。 docs说:

It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.

关于java - 如何在动画结束后开始新的 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13104051/

相关文章:

CSS3 动画淡出

java - 将 for 循环转换为 java 8 流

java - 关于 == 的编程逻辑

android - 在 Android 中如何区分 MotionEvent.ACTION_UP 和将手指拖离屏幕?

animation - react 原生动画 : Spring Speed

css - 旋转svg动画的起点

java - jersey json 尝试解码到同一对象

java - 使用左连接在 postgres 数据库中进行 SQL 查询

java - JSoup - 选择所有评论

android - Xamarin Android 音频 DSP