[Android]点击按钮进入下一个Activity时显示动画效果

动画效果写在xml里,

在按键的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 );
        }

那么Intent和animation是同时执行的,看不到动画效果,

 

应该这样写——加入一个AnimationListener

 

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

 

posted @ 2010-12-14 13:08  木乃猫  阅读(7971)  评论(0编辑  收藏  举报