咱们常常有些需求须要用到轮播的逐帧动画,能够用线程实现,固然android系统为咱们提供了更简约简单的实现手段——Animation-list。 android
首先下面是一段XML,你能够新建一个XML存放在项目的res/drawable目录下面。 布局
<?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/charging_01" android:duration="500"></item> <item android:drawable="@drawable/charging_02" android:duration="500"></item> <item android:drawable="@drawable/charging_03" android:duration="500"></item> </animation-list>其中android:oneshot="false" 这个是表示是否只展现一次,设为false就表示会循环播放,android:duration="500"这个是表示当前图片停留的时间,单位为毫秒。
第二步:写一个布局文件,在这里我就不写了,在一个控件里面,好比ImageView,设置它的背景图片为上面新建好的那个动画xml便可。 动画
第三步:开启动画,下面的代码中mChargingLogo是我写的ImageView控件,经过ImageView.getBackgroud得到ImageView的背景动画,而后经过AnimationDrawable 启动动画便可,中止动画可以使用mAnimationDrawable.stop(); spa
AnimationDrawable mAnimationDrawable = (AnimationDrawable) mChargingLogo.getBackground();
mAnimationDrawable.start();
线程