2013-05-29 65 views
1

當我啓動模擬器時,動畫僅播放動畫的第一幀,坐在計時器的持續時間內,然後啓動活動。Android Frame 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/title1" android:duration="200" /> 
<item android:drawable="@drawable/title2" android:duration="200" /> 
<item android:drawable="@drawable/title3" android:duration="200" /> 
<item android:drawable="@drawable/title4" android:duration="200" /> 
<item android:drawable="@drawable/title5" android:duration="200" /> 
<item android:drawable="@drawable/title6" android:duration="200" /> 
<item android:drawable="@drawable/title7" android:duration="200" /> 
<item android:drawable="@drawable/title8" android:duration="200" /> 
<item android:drawable="@drawable/title9" android:duration="200" /> 
<item android:drawable="@drawable/title10" android:duration="200" /> 
<item android:drawable="@drawable/title11" android:duration="200" /> 
</animation-list> 

這是我的佈局XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
> 

<ImageView 
android:id="@+id/gyro" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_centerInParent="true" 
/> 

這是我的java文件

public void onCreate(Bundle savedInstanceState) { 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splash); 
    // Start the animation (looped playback by default). 
    ImageView splash = (ImageView) findViewById(R.id.gyro); 
    splash.setBackgroundResource(R.drawable.title); 
    AnimationDrawable splashAnimation = (AnimationDrawable) splash.getBackground(); 
    splashAnimation.start(); 


    Thread logoTimer = new Thread(){ 
     public void run(){ 
     try{ 
     int logoTimer = 0; 
      while(logoTimer <10000){ 
      sleep(100); 
      logoTimer = logoTimer + 100; 
      }//end of while loop 
      //mpsplash.stop(); 
      startActivity(new Intent("tv.bScienceFiction.scrip.or.scrap.CLEARSCREEN")); 
      } catch (InterruptedException e) { 
       //TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     finally{ 
      finish(); 
     }//end of finally 

     }//end of run 

    };//end of new Thread 
    logoTimer.start(); 
} 

回答

0

後,從UI線程啓動它您退出onCreate

splash.postDelayed(new Runnable() { 
     public void run() { 
     splashAnimation.start(); 
     } 
    }, 200); 
+0

你太棒了。這工作完美。謝謝。我一直在撞牆撞牆。我能找到的每一個教程都沒有解決這個問題。謝謝。 –

+1

如果此解決方案適用於您,請將其標記爲「已接受」 - 如果他們有同樣的問題,這將有助於其他人發現它 – msh

+0

是的,它可行。但爲什麼? –

相關問題