首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

逐帧动画片入门

2012-06-28 
逐帧动画入门简单来讲,逐帧动画就是将一幅一幅图连起来播放,指定每一帧的持续时间,一般动画图片不要太大,

逐帧动画入门

简单来讲,逐帧动画就是将一幅一幅图连起来播放,指定每一帧的持续时间,一般动画图片不要太大,否则会发生内存溢出异常。

主要要点:

1、定义动画资源,范例如下:

?

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

android:oneshot="false">

? ? <item android:drawable="@drawable/ball1" android:duration="50" />

? ? <item android:drawable="@drawable/ball2" android:duration="50" />

? ? <item android:drawable="@drawable/ball3" android:duration="50" />

? ? <item android:drawable="@drawable/ball4" android:duration="50" />

? ? <item android:drawable="@drawable/ball5" android:duration="50" />

? ? <item android:drawable="@drawable/ball6" android:duration="50" />

? ? <item android:drawable="@drawable/ball7" android:duration="50" />

? ? <item android:drawable="@drawable/ball8" android:duration="50" />

? ? <item android:drawable="@drawable/ball9" android:duration="50" />

?</animation-list>

2、获得动画元素,范例代码如下:

ImageView imgView = (ImageView) findViewById(R.id.imageView);

3、关联动画元素和动画资源,范例代码如下:

imgView.setBackgroundResource(R.drawable.frame_animation);

AnimationDrawable frameAnimation = (AnimationDrawable) imgView.getBackground();

4、启动动画、关闭动画,范例代码如下:

?

if (frameAnimation.isRunning()) {

? frameAnimation.stop();

} else {

? frameAnimation.start();

}

5、默认情况下,动画是循环播放的,如果只播放一次可通过下面的代码实现:

frameAnimation.setOneShot(true);

6、在每播放一遍后插入内容:

frameAnimation.addFrame(getResources().getDrawable(R.drawable.ic_launcher), 80);

热点排行