帧动画,顾名思义就是一帧一帧播放的动画,利用多张图片一张一张
进行播放。接下来我们通过在drawable文件夹中使用xml文件来定义帧动画。
代码如下:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
其中android:oneshot="true"当为true时,代表动画播放一次,为false时,
动画无限循环播放。
然后在activity中使用imageview控件显示。代码如下:
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackgroundResource(R.drawable.frame);
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
ad.start();
进行播放。接下来我们通过在drawable文件夹中使用xml文件来定义帧动画。
代码如下:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
其中android:oneshot="true"当为true时,代表动画播放一次,为false时,
动画无限循环播放。
然后在activity中使用imageview控件显示。代码如下:
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setBackgroundResource(R.drawable.frame);
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
ad.start();