帧动画
播放一组定义好的图,对应AnimationDrawable类
使用方法:
在drawable下新建一个xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/img1" android:duration="500"/>
<item android:drawable="@drawable/img2" android:duration="500"/>
<item android:drawable="@drawable/img3" android:duration="500"/>
<item android:drawable="@drawable/img4" android:duration="500"/>
</animation-list>
在通过drawable作为背景来播放动画
Button button = (Button) findViewById(R.id.test_btn);
button.setBackgroundResource(R.drawable.animation);
AnimationDrawable animationDrawable = (AnimationDrawable) button.getBackground();
animationDrawable.start();
帧动画比较容易OOM,谨慎使用