2012-01-18 100 views
0

如何在动画结束后开始活动。 我已经在xml中添加了android:oneshot =“true”,但是如何在此动画停止后开始一个新活动 。我附上了下面的整个代码。 请让我知道如何开始新的活动。如何在Android动画结束后启动开始活动

package com.appsolut.example.animation; 


    import android.app.Activity; 
    import android.content.Intent; 
    import android.graphics.drawable.AnimationDrawable; 
    import android.os.Bundle; 
    import android.widget.ImageView; 

    public class Animation extends Activity { 

    ImageView animation; 


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


    } 

    @Override 

    public void onWindowFocusChanged (boolean hasFocus) { 
     super.onWindowFocusChanged(hasFocus); 
     AnimationDrawable frameAnimation = 
      (AnimationDrawable) animation.getBackground(); 

     if(hasFocus) {   

      frameAnimation.start(); 


     } else { 
      frameAnimation.stop(); 

     } 

    } 


    public void onStart() { 
     { 
      super.onStart(); 

      animation = (ImageView)findViewById(R.id.imageAnimation); 

      animation.setBackgroundResource(R.drawable.animation);  

     } 
    } 
} 

animation.xml

<?xml version="1.0" encoding="utf-8"?> 
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
     android:oneshot="true" > 

     <item android:drawable="@drawable/img00000" android:duration="500" /> 
     <item android:drawable="@drawable/img00001" android:duration="500" /> 
     <item android:drawable="@drawable/img00002" android:duration="500" /> 
     <item android:drawable="@drawable/img00003" android:duration="500" /> 
     <item android:drawable="@drawable/img00004" android:duration="500" /> 
     <item android:drawable="@drawable/img00005" android:duration="500" /> 
     <item android:drawable="@drawable/img00006" android:duration="500" /> 
     <item android:drawable="@drawable/img00007" android:duration="500" /> 
     <item android:drawable="@drawable/img00008" android:duration="500" /> 
     <item android:drawable="@drawable/img00009" android:duration="500" /> 
     <item android:drawable="@drawable/img00010" android:duration="500" /> 

    </animation-list> 
+0

加油的人,至少尝试不要只问的答案... – JoxTraex 2012-01-18 02:46:25

+0

嗨Mr.JoxTraex,我已经尝试了许多方法,但它一直崩溃或动画只是停止了我想附加甚至是代码,但认为它会使这个过程变得复杂。我对android中的动画很陌生,所以需要一段时间,谢谢你的动机,也会这样做。 – 2012-01-18 11:46:28

回答

2
你的动画做任何你想要它 onAnimationEnd()方法

使用和AnimationListener

+0

谢谢先生,但是如何在onAnimationStart()中传递相同的代码? – 2012-01-18 21:24:34

+0

你想在动画开始()上做什么? – 2012-01-18 23:08:31

+0

您好Mr.dtmilano.I希望它显示android:duration =“500”的图像,我还能如何实现它? – 2012-01-20 16:36:15

0

在您的动画调用之后创建一个新的Intent(来自Intent类)。

意图myIntent = new Intent(context,newActivity.class); startActivity(myIntent);

上下文可以的getContext()或getBaseContext()

这应该工作。此外不要忘记在AndroidManifest中声明您的新活动,否则应用程序将崩溃!

希望这有助于。

0

使用hasEnded()方法检查是否结束,然后如果它已经调用您的意图打开新的活动。

它应该工作

问候

+0

谢谢斯里兰卡,但我无法找到应用此解决方案的地方。 – 2012-01-18 21:24:39

相关问题