上一篇說了說Android tween動畫,這一篇所以說Android Frame動畫吧,這個動畫相對來說比較簡單,就是吧圖片按照一定的順序排列並播放出來。我這裏寫的是一個進度條動畫。下面是主要代碼:
佈局xml文件,用的是一個imageviewe
<ImageView
android:id="@+id/loadingImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/sf_progress_dialog_anim"
android:layout_gravity="center_horizontal"/>
動畫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/sf_progress_1"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_2"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_3"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_4"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_5"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_6"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_7"
android:duration="200"/>
<item
android:drawable="@drawable/sf_progress_8"
android:duration="60"/>
</animation-list>
只要加載佈局文件,就能看到上圖中點一點點旋轉,類似加載進度條,這裏只列舉了幾個圖片,是不是很簡單。
當然,也可以在代碼中設置其中的動畫效果
imageview.setBackgroundResource(R.anim.anim);
AnimationDrawable drawable=imageview.getBackground();
drawable.start();
這樣也能達到動畫效果。