动画之前活动的变化 [英] Animation BEFORE activity change

查看:101
本文介绍了动画之前活动的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些简单的,但我不明白为什么它不工作。
我正在试图做的是:当我触摸ImageView的,它会显示在它的动画。然后,只有当动画结束,将开始新的活动。
相反,会发生什么情况是,新的活动马上开始与动漫不显示。

I'm trying to do something simple, but I can't understand why it's not working.
What I'm trying to do is: when I touch an ImageView, it will show an animation on it. And then, only when that animation ends it will start the new activity.
Instead, what happens is that the new activity starts right away and the animation is not shown.

下面是动画的xml:

<rotate android:interpolator="@android:anim/decelerate_interpolator"
    android:fromDegrees="-45"
    android:toDegrees="-10"
    android:pivotX="90%"
    android:pivotY="10%"
    android:repeatCount="3"
    android:fillAfter="false"
    android:duration="10000" />

这是code我用它来称呼它:

And this is the code I use to call it:

public void onCreate( Bundle savedInstanceState )
{
    final ImageView ib = (ImageView)this.findViewById( R.id.photo );
    ib.setOnClickListener( new OnClickListener( ) {

        @Override
        public void onClick( View v )
        {
            Animation hang_fall = AnimationUtils.loadAnimation( Curriculum.this, R.anim.hang_fall );
            v.startAnimation( hang_fall );
            Intent i = new Intent( ThisActivity.this, NextActivity.class );
            ThisActivity.this.startActivity( i );
        }// end onClick
    } );
}// end onCreate

正如你看到的我试图把一个loooong时间为动画,但它不工作。该NextActivity马上开始,它不会等待动画ThisActivity完成。
为什么出现这种情况你知道吗?

As you see I tried putting a loooong time for the animation, but it doesn't work. The NextActivity starts right away, it doesn't wait for the animation in ThisActivity to finish.
Any idea on why this happens?

推荐答案

那是因为你开始的意图和动画在同一时间。您需要启动的意图后,动画已经结束了,是这样的:

That's because you're starting the intent and the animation at the same time. You need to start the intent after the animation is over, like this:

@Override
public void onClick( View v )
{
    Animation hang_fall = AnimationUtils.loadAnimation( Curriculum.this, R.anim.hang_fall );
    hang_fall.setAnimationListener(new Animation.AnimationListener()
        {
            public void onAnimationEnd(Animation animation)
            {
                Intent i = new Intent( ThisActivity.this, NextActivity.class );
                ThisActivity.this.startActivity( i );
            }

            public void onAnimationRepeat(Animation animation)
            {
                // Do nothing!
            }

            public void  onAnimationStart(Animation animation)
            {
                // Do nothing!
            }
        });
    v.startAnimation( hang_fall );
}// end onClick

这篇关于动画之前活动的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆