简体   繁体   English

在开始新活动之前允许动画完成

[英]Allow an animation to finish before starting a new activity

I would like to perform an animation on an image before switching to a new activity. 我想在切换到新活动之前在图像上执行动画。 I also want to make sure that the animation is fully completed before the new activity starts. 我还想确保在新活动开始之前动画已完全完成。 Below is the code that I am using to accomplish the task. 下面是我用来完成任务的代码。

public boolean onTouch(View view, MotionEvent event) {
        Animation shake = AnimationUtils.loadAnimation(ViewReadingActivity.this, R.anim.shake);
        imgAries.startAnimation(shake);

        Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
        startActivity(intent);
        return true;
    }   

The problem with this is that the animation does not run to completion before the new activity is presented and the animation will continue to run from where it was left. 问题在于动画在呈现新活动之前不会运行完成,并且动画将继续从其离开的位置开始运行。 Is there a better way to accomplish this? 有没有更好的方法可以做到这一点?

use like this here you can have animation listner 这样使用,您可以拥有动画列表器

shake.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationRepeat(Animation arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationEnd(Animation arg0) {
       Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
    startActivity(intent);

    }
});

do this: 1. animation.setAnimationListener(), implement the methods 2. onanimationend method , write in the code to start a new activity 为此:1.animation.setAnimationListener(),实现方法2.onanimationend方法,编写代码以开始新的活动

m late :( 我晚:(

Animation Listener Already Contains the Method called as onAnimationEnd @override it on your imgAries Animation Listener 动画侦听器已包含名为onAnimationEnd的方法@在您的imgAries动画侦听器上覆盖它

onAnimationEnd(Animation anim){
//Start you Activity here using Intent
Intent i=new Intent(this,//Your next Activity);
startActivity(i);

 }

That it...Now you can go to Next Activity on Animation End...Thks 知道了...现在,您可以转到“动画结束”的“下一个活动”。

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

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