前言
Frame
动画就像GIF图片,通过一系列Drawable
依次显示来模拟动画的效果。
1. 帧动画配置
在"drawable"
目录下配置文件drawable_frame.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/gif_00" android:duration="100"/>
<item android:drawable="@drawable/gif_01" android:duration="100"/>
<item android:drawable="@drawable/gif_02" android:duration="100"/>
<item android:drawable="@drawable/gif_03" android:duration="100"/>
<item android:drawable="@drawable/gif_04" android:duration="100"/>
<item android:drawable="@drawable/gif_05" android:duration="100"/>
<item android:drawable="@drawable/gif_06" android:duration="100"/>
<item android:drawable="@drawable/gif_07" android:duration="100"/>
<item android:drawable="@drawable/gif_08" android:duration="100"/>
<item android:drawable="@drawable/gif_09" android:duration="100"/>
<item android:drawable="@drawable/gif_10" android:duration="100"/>
<item android:drawable="@drawable/gif_11" android:duration="100"/>
<item android:drawable="@drawable/gif_12" android:duration="100"/>
<item android:drawable="@drawable/gif_13" android:duration="100"/>
<item android:drawable="@drawable/gif_14" android:duration="1000"/>
</animation-list>
oneshot
,true
只展示一遍,false
会不停的循环播放动画drawable
,展示的图片资源duration
,展示该图片的时间长度
2. 加载帧动画
使用ImageView
加载
<ImageView
android:id="@+id/iv_frame"
androi8d:layout_width="160dp"
android:layout_height="110dp"
android:src="@drawable/drawable_frame" />
在代码中开始动画和结束
ImageView ivFrame = findViewById(R.id.iv_frame);
AnimationDrawable mDrawable = (AnimationDrawable) ivFrame.getDrawable();
mDrawable.start();
//结束动画 mDrawable.stop();
效果如下
相关文章
Animation动画
帧动画
属性动画
组件动画
Transition动画