在可绘制动画结束时转到新活动

时间:2013-12-07 18:15:14

标签: java android

你好,我已经尝试在Drawable动画完成后开始一项活动,但是我无法做到这一点,所以我在这里向你展示我给出的代码请帮助我找到解决方案

 package com.example.hole;
   import android.os.Bundle;
   import android.app.Activity;
   import android.content.Intent;
   import android.graphics.drawable.AnimationDrawable;
   import android.widget.ImageView;


    public class MainActivity extends Activity {

            ImageView view;
        AnimationDrawable frameAnimation;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // Typecasting the Image View
                    view = (ImageView) findViewById(R.id.imageAnimation);
                    // Setting animation_list.xml as the background of the image view
                    view.setBackgroundResource(R.drawable.ass);
                    // Typecasting the Animation Drawable
                    frameAnimation = (AnimationDrawable) view.getBackground();
        } 
        // Called when Activity becomes visible or invisible to the user
        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
              if (hasFocus) 
              {
            // Starting the animation when in Focus
                  frameAnimation.start();
            } 
             else
              {
                // Stoping the animation when not in Focus
                 frameAnimation.stop();

              }
                }
    }

1 个答案:

答案 0 :(得分:0)

您可以通过在onCreate方法中调用方法frameAnimation.setAnimationListener()来为动画设置AnimationListener