首先可以先定义一个逐帧播放的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 <item 10 android:drawable="@drawable/on_002" 11 android:duration="100"/> 12 13 <item 14 android:drawable="@drawable/on_003" 15 android:duration="100"/> 16 17 <item 18 android:drawable="@drawable/on_004" 19 android:duration="100"/> 20 21 <item 22 android:drawable="@drawable/on_005" 23 android:duration="100"/> 24 25 <item 26 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();