帧动画,顾名思义就是一帧一帧播放的动画,利用多张图片一张一张
进行播放。接下来我们通过在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();
帧动画实现详解
本文介绍了一种通过XML文件定义帧动画的方法,详细解释了如何在Android的drawable文件夹内创建帧动画,并展示了如何使用ImageView控件播放这些帧动画。
1071

被折叠的 条评论
为什么被折叠?



