Drawable Animation即我们所说的帧动画,表示将一组有序的图片按顺序展示,这是一种传统的动画,就像播放胶片电影一
样。要实现帧动画,就要用到AnimationDrawable类;它里面可以封装一组有序drawable资源。他有两种生成方式,一种是利用
xml,另一种是纯代码;
1,利用xml声明:res/drawable/animation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true"
android:oneshot="false">
<item android:drawable="@drawable/bol_paars" android:duration="200"></item>
<item android:drawable="@drawable/bol_green" android:duration="200"></item>
<item android:drawable="@drawable/bol_blue" android:duration="200"></item>
<item android:drawable="@drawable/bol_red" android:duration="200"></item>
<item android:drawable="@drawable/bol_yellow" android:duration="200"></item>
</animation-list>
引用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_aa"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="@null"
android:layout_centerInParent="true"
android:src="@drawable/animation_list"/>
</RelativeLayout>
调用代码:
AnimationDrawable ad=(AnimationDrawable) iv_aa.getDrawable();
ad.start();
2,纯代码实现:
AnimationDrawable add=new AnimationDrawable();
add.addFrame(getResources().getDrawable(R.drawable.bol_blue), 200);
add.addFrame(getResources().getDrawable(R.drawable.bol_green), 200);
add.addFrame(getResources().getDrawable(R.drawable.bol_paars), 200);
add.addFrame(getResources().getDrawable(R.drawable.bol_red), 200);
add.addFrame(getResources().getDrawable(R.drawable.bol_yellow), 200);
add.setOneShot(false);
iv_aa.setImageDrawable(add);
add.start();