Android播放多张图片形成一个动画效果

来源:互联网 发布:淘宝网帮助中心 编辑:程序博客网 时间:2024/05/21 10:49
转自:http://bbs.51cto.com/thread-990032-1-1.html

andriod里可以逐帧的播放图片,然后产生一种动态的效果,准备好几张连续的图片,然后在于源程序res文件夹下建立anim文件夹,然后新建一个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();//启动
原创粉丝点击