软件编程
位置:首页>> 软件编程>> Android编程>> Android播放多张图片形成的一个动画示例

Android播放多张图片形成的一个动画示例

作者:pku_android  发布时间:2021-08-23 18:07:32 

标签:Android,图片,动画

本文实例讲述了Android播放多张图片形成的一个动画。分享给大家供大家参考,具体如下:

在Android里可以逐帧的播放图片,然后产生一种动态的效果,准备好几张连续的图片,然后在于源程序res文件夹下建立anim文件夹,然后新建一个XML

XML代码如下:


<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/c1" android:duration="200" />
<item android:drawable="@drawable/c2" android:duration="200" />
<item android:drawable="@drawable/c3" android:duration="200" />
<item android:drawable="@drawable/c4" android:duration="200" />
<item android:drawable="@drawable/c5" android:duration="200" />
<item android:drawable="@drawable/c6" android:duration="200" />
</animation-list>

其中c1,c2,c3,c4,c5,c6是加入的图片的名称。

在窗体里面放置一个ImageView控件,并在代码中编写:


_imageView1 =(ImageView)findViewById(R.id.imageView1);//放置的ImageView控件
//设置动画背景
_imageView1.setBackgroundResource(R.anim.animation_list);//其中R.anim.animation_list就是上一步准备的动画描述文件的资源名
//获得动画对象
_animaition = (AnimationDrawable)_imageView1.getBackground();

最后,就可以启动动画了,代码如下:


//是否仅仅启动一次?
_animaition.setOneShot(false);
if(_animaition.isRunning())//是否正在运行?
{
_animaition.stop();//停止
}
_animaition.start();//启动

希望本文所述对大家Android程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com