1. 程式人生 > >Android之動畫-逐幀動畫

Android之動畫-逐幀動畫

介紹:“逐幀動畫”,就是將多張圖按照播放動畫片那樣,從第一張圖片播放到最後一張。

animation.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/image_progress_wait_gray_01" android:duration="100"
/>
<item android:drawable="@drawable/image_progress_wait_gray_02" android:duration="100"/> ...... <item android:drawable="@drawable/image_progress_wait_gray_26" android:duration="100"/> </animation-list>

oneshot true:只迴圈播放一次,false:一直迴圈播放。
duration 設定這一幀的停留時間,時間單位為毫秒。

把動畫賦給ImageView

1、xml程式碼中使用
<ImageView android:id="@+id/animationIV"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:padding="5px"  
            android:src="@drawable/animation1"/> 

2、java動態設定
mImage.setImageResource(R.drawable.progress
_wait); animationDrawable = (AnimationDrawable)

開啟/關閉動畫

AnimationDrawable animationDrawable = (AnimationDrawable) mImage.getDrawable();
//...需要判斷下“animationDrawable”是否為空
animationDrawable.start();//開啟動畫
animationDrawable.stop();//關閉動畫

備註:目前逐幀動畫播放停止後,再次啟動,會從第一幀再次播放。