有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我对Android很陌生,我找不到关于如何在anim end上启动新活动的线索

这是我的密码:

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();        
        }

        });

    }

}

共 (1) 个答案

  1. # 1 楼答案

    据我所知,没有回调机制来确定AnimationDrawable何时完成迭代。您可以做的是查询帧数和每帧的延迟。把这些加起来,用这个持续时间写一篇延迟的文章。在该回调中,您可以开始第二个活动

    请注意,以这种方式启动动画有点危险。主席说:

    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.