一个简单帧动画
首先是先写好drawable文件
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@mipmap/marker_0" android:duration="150" />
<item android:drawable="@mipmap/marker_1" android:duration="150" />
<item android:drawable="@mipmap/marker_2" android:duration="150" />
<item android:drawable="@mipmap/marker_3" android:duration="150" />
<item android:drawable="@mipmap/marker_4" android:duration="150" />
<item android:drawable="@mipmap/marker_5" android:duration="150" />
<item android:drawable="@mipmap/marker_6" android:duration="150" />
<item android:drawable="@mipmap/marker_7" android:duration="150" />
<item android:drawable="@mipmap/marker_8" android:duration="150" />
<item android:drawable="@mipmap/marker_9" android:duration="150" />
<item android:drawable="@mipmap/marker_10" android:duration="150" />
<item android:drawable="@mipmap/marker_11" android:duration="150" />
<item android:drawable="@mipmap/marker_12" android:duration="150" />
<item android:drawable="@mipmap/marker_13" android:duration="150" />
<item android:drawable="@mipmap/marker_14" android:duration="150" />
<item android:drawable="@mipmap/marker_15" android:duration="150" />
<item android:drawable="@mipmap/marker_16" android:duration="150" />
<item android:drawable="@mipmap/marker_17" android:duration="150" />
<item android:drawable="@mipmap/marker_18" android:duration="150" />
<item android:drawable="@mipmap/marker_19" android:duration="150" />
<item android:drawable="@mipmap/marker_20" android:duration="150" />
</animation-list>
接下来就是启动动画和停止动画,以下代码在activity中写:
public void startAnimation(){ markerIcon.setImageResource(R.drawable.marker_anim_drawable); AnimationDrawable animationDrawable = (AnimationDrawable)markerIcon.getDrawable(); animationDrawable.start(); }markerIcon 是显示图片的控件 ,marker_anim_drawable 这个是上面动画drawable的文件名
public void endAnimation(){ Drawable bd = markerIcon.getDrawable(); if(bd != null && bd instanceof AnimationDrawable){ AnimationDrawable animationDrawable = (AnimationDrawable)bd; if(bd != null){ animationDrawable.stop(); } } }停止动画的时候做一下判断。也可以设置停止之后再显示新的图标之类的自己的操作