逐帧动画的xml代码:
1 <?xml version="1.0" encoding="utf-8"?> 2 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 3 android:oneshot="true" > 4 5 <item 6 android:drawable="@drawable/img10" 7 android:duration="1000"> 8 </item> 9 <item 10 android:drawable="@drawable/img9" 11 android:duration="1000"> 12 </item> 13 <item 14 android:drawable="@drawable/img8" 15 android:duration="1000"> 16 </item> 17 <item 18 android:drawable="@drawable/img7" 19 android:duration="1000"> 20 </item> 21 <item 22 android:drawable="@drawable/img6" 23 android:duration="1000"> 24 </item> 25 <item 26 android:drawable="@drawable/img5" 27 android:duration="1000"> 28 </item> 29 <item 30 android:drawable="@drawable/img4" 31 android:duration="1000"> 32 </item> 33 <item 34 android:drawable="@drawable/img3" 35 android:duration="1000"> 36 </item> 37 <item 38 android:drawable="@drawable/img2" 39 android:duration="1000"> 40 </item> 41 <item 42 android:drawable="@drawable/img1" 43 android:duration="1000"> 44 </item> 45 <item 46 android:drawable="@drawable/img0" 47 android:duration="1000"> 48 </item> 49 50 </animation-list>
对应的android代码:
1 public class MainActivity extends Activity { 2 3 private ImageView img; 4 private Button button; 5 private AnimationDrawable animationDrawable; 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_main); 10 int duration=0; // duration是记录第一个动画播放的总时间 11 img=(ImageView) findViewById(R.id.imageView); 12 img.setImageResource(R.drawable.item_anim); 13 animationDrawable=(AnimationDrawable) img.getDrawable(); 14 img.post(new Runnable() { //在异步线程中执行启动的方法 15 16 @Override 17 public void run() { 18 // TODO Auto-generated method stub 19 animationDrawable.start(); //启动动画 20 } 21 }); 22 for(int i=0;i<animationDrawable.getNumberOfFrames();i++){ 23 duration+=animationDrawable.getDuration(i); //计算动画播放的时间 24 25 } 26 Handler handler=new Handler(); 27 handler.postDelayed(new Runnable() { 28 public void run() { 29 Intent intent=new Intent(MainActivity.this,TestActivity.class); //Intent 意图 在执行完动画的时候 跳转至另一个页面 30 startActivity(intent); 31 32 } 33 }, duration); 34 35 } 36 37 38 }
android 逐帧动画的播放与播放结束操作对象,布布扣,bubuko.com
原文:http://www.cnblogs.com/-canyue/p/3703381.html