本文實例講述了Android播放多張圖片形成的一個動畫。分享給大家供大家參考,具體如下:
在Android里可以逐幀的播放圖片,然后產生一種動態的效果,準備好幾張連續的圖片,然后在于源程序res文件夾下建立anim文件夾,然后新建一個XML
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/c1" android:duration="200" /><item android:drawable="@drawable/c2" android:duration="200" /><item android:drawable="@drawable/c3" android:duration="200" /><item android:drawable="@drawable/c4" android:duration="200" /><item android:drawable="@drawable/c5" android:duration="200" /><item android:drawable="@drawable/c6" android:duration="200" /></animation-list>
其中c1,c2,c3,c4,c5,c6是加入的圖片的名稱。
在窗體里面放置一個ImageView控件,并在代碼中編寫:
_imageView1 =(ImageView)findViewById(R.id.imageView1);//放置的ImageView控件//設置動畫背景_imageView1.setBackgroundResource(R.anim.animation_list);//其中R.anim.animation_list就是上一步準備的動畫描述文件的資源名//獲得動畫對象_animaition = (AnimationDrawable)_imageView1.getBackground();
最后,就可以啟動動畫了,代碼如下:
//是否僅僅啟動一次?_animaition.setOneShot(false);if(_animaition.isRunning())//是否正在運行?{_animaition.stop();//停止}_animaition.start();//啟動
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答