gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:30:51 24 4
gpt4 key购买 nike

我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com