Drawable Animation -- 使用多幅图片实现动画

来源:互联网 发布:浙江省软件考试网 编辑:程序博客网 时间:2024/05/16 09:05

在Andrio的中,可以使用多幅图片实现动画效果。

首先定义一个以 <animation-list>为根节点的xml文件,命名为 anim.xml 放在 res/drawable/目录下。

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:oneshot="true">    <item android:drawable="@drawable/image1" android:duration="200" />    <item android:drawable="@drawable/image2" android:duration="200" />    <item android:drawable="@drawable/image3" android:duration="200" /></animation-list>


然后,在控件中使用此资源文件 

ImageView image = (ImageView) findViewById(R.id.rocket_image);image.setBackgroundResource(R.drawable.rocket_thrust);AnimationDrawable animation = (AnimationDrawable) image.getBackground(); 

最后,在需要的时候启动动画即可。

animation.start();