Android中的动画分为三种:View动画、帧动画、属性动画
帧动画
帧动画是顺序播放一组预先定义好的图片,类似电影播放。系统提供了一个AnimationDrawable类来使用帧动画。
使用:
首先在res/drawable/目录下创建一个xml文件,比如test_frame_animation.xml
<?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/imag1" android:duration="500" />
<item android:drawable="@drawable/imag2" android:duration="500" />
<item android:drawable="@drawable/imag3" android:duration="500" />
</animation-list>
然后将Drawable作为背景设置给view
Button button = (Button) findViewById(R.id.test);
button.setBackgroundResource(R.drawable.test_frame_animation);
AnimationDrawable drawable = (AnimationDrawable) button.getBackground;
drawable.start();
帧动画容易引起OOM,所以在使用时尽量避免加载过大尺寸的图片