如何停止FrameAnimation并启动一个新的Activity?(Intent)

时间:2013-10-06 17:37:52

标签: android android-intent android-activity android-animation

 public class Mainpage extends Activity {

// Declaring an Image View and an Animation Drawable
    ImageView view;
    ImageView view1;
    AnimationDrawable frameAnimation;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainpage);

        // 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.animation_list);

        // 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)

frameAnimation.stop();方法用于停止动画。要开始新的Activity,您可以使用以下代码 -

startActivity(Mainpage.this, newActivity.class);

Intent i = new Intent(this, newActivity.class);
startActivity(i);

您可以使用您想要的Activity名称来代替newActivity