帧动画
1、导入以下图片放入drawable目录下:
pic_cartoon_fan_1.png
pic_cartoon_fan_2.png
pic_cartoon_fan_3.png
pic_cartoon_fan_4.png
pic_cartoon_fan_5.png
2、创建fan.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pic_cartoon_fan_1" android:duration="100"/>
<item android:drawable="@drawable/pic_cartoon_fan_2" android:duration="100"/>
<item android:drawable="@drawable/pic_cartoon_fan_3" android:duration="100"/>
<item android:drawable="@drawable/pic_cartoon_fan_4" android:duration="100"/>
<item android:drawable="@drawable/pic_cartoon_fan_5" android:duration="100"/><!--duration是帧动画的旋转速度-->
</animation-list>
3、创建imageview控件
<ImageView
android:layout_centerInParent="true"
android:id="@+id/fan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/fan"/><!--记得引用创建的fan.xml-->
4、在MainActivity开启帧动画
AnimationDrawable fanRoll = (AnimationDrawable)fan.getDrawable();
fanRoll.start();//开启旋转
fanRoll.stop();//关闭旋转