首先可以先定義一個逐幀播放的xml:
1 <?xml version="1.0" encoding="utf-8"?> 2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 3 android:oneshot="false" > 4 5 <item 6 android:drawable="@drawable/on_001" 7 android:duration="100"/> 8 9 <item10 android:drawable="@drawable/on_002"11 android:duration="100"/>12 13 <item14 android:drawable="@drawable/on_003"15 android:duration="100"/>16 17 <item18 android:drawable="@drawable/on_004"19 android:duration="100"/>20 21 <item22 android:drawable="@drawable/on_005"23 android:duration="100"/>24 25 <item26 android:drawable="@drawable/on_006"27 android:duration="100"/>28 </animation-list>
然後在代碼中定義出AnimationDrawable對象,並設定到view的background上,然後設定開始播放就可以了:
1 AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(2 R.drawable.bootanimation);3 mView.setBackgroundDrawable(ad);4 ad.start();