简体   繁体   English

单击动画完成,然后再进行其他活动

[英]Finish the animation on click before going to another activity

I have an animation that is to be displayed on click of an image view and finish the animation before going to another activity.I have been trying to do this. 我有一个要在单击图像视图时显示的动画,并在进行其他活动之前先完成动画。我一直在尝试这样做。

Here is my code : 这是我的代码:

public void myAnimation() 
    AnimationDrawable animation;
    animation = new AnimationDrawable();
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_monotone),
            1000);
    animation.addFrame(getResources()
            .getDrawable(R.drawable.large_ring_eal), 1000);
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_blue), 1000);
    animation.addFrame(
            getResources().getDrawable(R.drawable.large_ring_monotone),
            1000);

    animation.setOneShot(true);
    img_big_2_back.setOnClickListener(new OnClickListener){
    img_big_2_back.setBackgroundDrawable(animation);

        try {
            animation.start();
            Thread.sleep(3000);

        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Intent i1 = new Intent(MAinACtivity.this,SecondActivity.class);
        startActivity(i1);
    });
}

Can any one let me know where i am going wrong 谁能让我知道我要去哪里了

Man, if your activity is getting called even before animation is finished, then try setting Animation Listener, you can start activity from there once animation finish callback is received. 伙计,如果您的活动甚至在动画制作完成之前就被调用,请尝试设置“动画侦听器”,您可以在收到动画制作完成回调后从那里开始活动。

http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html

First of all, why there is a Thread Sleep in your code? 首先,为什么您的代码中存在Thread Sleep That's not the way to wait for animation to get over. 那不是等待动画结束的方法。 Try the answers of this thread . 尝试此线程的答案。 You can use the method described in this answer 您可以使用此答案中描述的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM