帧动画在Android动画中是比较简单的,是按照一定顺序播放一组图片,像快速的PPT一样,在实现帧动画时,首先在Drawable下创建一个XML文件,如下所示<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/record_animate_01" android:duration="200" />
<item android:drawable="@drawable/record_animate_02" android:duration="200" />
<item android:drawable="@drawable/record_animate_03" android:duration="200" />
<item android:drawable="@drawable/record_animate_04" android:duration="200" />
<item android:drawable="@drawable/record_animate_05" android:duration="200" />
<item android:drawable="@drawable/record_animate_06" android:duration="200" />
<item android:drawable="@drawable/record_animate_07" android:duration="200" />
<item android:drawable="@drawable/record_animate_08" android:duration="200" />
<item android:drawable="@drawable/record_animate_09" android:duration="200" />
<item android:drawable="@drawable/record_animate_10" android:duration="200" />
<item android:drawable="@drawable/record_animate_11" android:duration="200" />
<item android:drawable="@drawable/record_animate_12" android:duration="200" />
<item android:drawable="@drawable/record_animate_13" android:duration="200" />
<item android:drawable="@drawable/record_animate_14" android:duration="200" />
</animation-list>
每个item都是一张图片,duration用于设定改图片展示的时间,然后在代码中作为背景进行播放
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/record_animate_01" android:duration="200" />
<item android:drawable="@drawable/record_animate_02" android:duration="200" />
<item android:drawable="@drawable/record_animate_03" android:duration="200" />
<item android:drawable="@drawable/record_animate_04" android:duration="200" />
<item android:drawable="@drawable/record_animate_05" android:duration="200" />
<item android:drawable="@drawable/record_animate_06" android:duration="200" />
<item android:drawable="@drawable/record_animate_07" android:duration="200" />
<item android:drawable="@drawable/record_animate_08" android:duration="200" />
<item android:drawable="@drawable/record_animate_09" android:duration="200" />
<item android:drawable="@drawable/record_animate_10" android:duration="200" />
<item android:drawable="@drawable/record_animate_11" android:duration="200" />
<item android:drawable="@drawable/record_animate_12" android:duration="200" />
<item android:drawable="@drawable/record_animate_13" android:duration="200" />
<item android:drawable="@drawable/record_animate_14" android:duration="200" />
</animation-list><span style="font-size:14px;">iv = (ImageView) findViewById(R.id.iv_drawable);
btn = (Button) findViewById(R.id.btn);
iv.setBackgroundResource(R.drawable.drawable_animation);
drawable = (AnimationDrawable) iv.getBackground();
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
drawable.start();
}
});</span>
这里找的是几个录制声音的图片,简单的连起来就是一个录制声音的图像
本文介绍如何在Android中实现帧动画,通过创建XML文件定义一系列图片及其显示时间,并在代码中设置为ImageView背景来播放动画。
2460

被折叠的 条评论
为什么被折叠?



