首页 > 系统 > Android > 正文

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

2019-10-23 20:08:52
字体:
来源:转载
供稿:网友

本文实例讲述了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程序设计有所帮助。


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表