本文实例为大家分享了利用animation-List实现帧动画的具体代码,供大家参考,具体内容如下
将要顺序播放的图片放在资源目录下
再drawable目录下新建animation1文件和animation2文件 一个是按顺序显示动画,一个是倒序显示动画,
顺序显示动画文件:animation1.xml
<?xml version="1.0" enCoding="utf-8"?> <!-- 根标签为animation-List,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画 根标签下,通过item标签对动画中的每一个图片进行声明 androID:duration 表示展示所用的该图片的时间长度 --> <animation-List xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:oneshot="true" > <item androID:drawable="@drawable/icon1" androID:duration="150"></item> <item androID:drawable="@drawable/icon2" androID:duration="150"></item> <item androID:drawable="@drawable/icon3" androID:duration="150"></item> <item androID:drawable="@drawable/icon4" androID:duration="150"></item> <item androID:drawable="@drawable/icon5" androID:duration="150"></item> <item androID:drawable="@drawable/icon6" androID:duration="150"></item> </animation-List>
倒序显示动画文件:animation2.xml
<?xml version="1.0" enCoding="utf-8"?> <!-- 根标签为animation-List,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画 根标签下,通过item标签对动画中的每一个图片进行声明 androID:duration 表示展示所用的该图片的时间长度 --> <animation-List xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:oneshot="true" > <item androID:drawable="@drawable/icon6" androID:duration="150"></item> <item androID:drawable="@drawable/icon5" androID:duration="150"></item> <item androID:drawable="@drawable/icon4" androID:duration="150"></item> <item androID:drawable="@drawable/icon3" androID:duration="150"></item> <item androID:drawable="@drawable/icon2" androID:duration="150"></item> <item androID:drawable="@drawable/icon1" androID:duration="150"></item> </animation-List>
布局文件
<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical"> <ImageVIEw androID:ID="@+ID/animationIV" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:padding="5px" androID:src="@drawable/animation1"/> <button androID:ID="@+ID/buttonA" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:padding="5px" androID:text="顺序显示" /> <button androID:ID="@+ID/buttonB" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:padding="5px" androID:text="停止" /> <button androID:ID="@+ID/buttonC" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:padding="5px" androID:text="倒序显示" /> </linearLayout>
Activity文件
package org.shuxiang.test; import androID.app.Activity; import androID.graphics.drawable.AnimationDrawable; import androID.os.Bundle; import androID.vIEw.VIEw; import androID.vIEw.VIEw.OnClickListener; import androID.vIEw.Window; import androID.Widget.button; import androID.Widget.ImageVIEw; public class Activity10 extends Activity { private ImageVIEw animationIV; private button buttonA,buttonB,buttonC; private AnimationDrawable animationDrawable; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestwindowFeature(Window.FEATURE_NO_Title); setContentVIEw(R.layout.test10); animationIV = (ImageVIEw) findVIEwByID(R.ID.animationIV); buttonA = (button) findVIEwByID(R.ID.buttonA); buttonB = (button) findVIEwByID(R.ID.buttonB); buttonC = (button) findVIEwByID(R.ID.buttonC); buttonA.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub animationIV.setimageResource(R.drawable.animation1); animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); } }); buttonB.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.stop(); } }); buttonC.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub animationIV.setimageResource(R.drawable.animation2); animationDrawable = (AnimationDrawable) animationIV.getDrawable(); animationDrawable.start(); } }); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的Android利用animation-list实现帧动画全部内容,希望文章能够帮你解决Android利用animation-list实现帧动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)