Android动画解析2-帧动画实现

本文介绍如何在Android中实现帧动画,通过创建XML文件定义一系列图片及其显示时间,并在代码中设置为ImageView背景来播放动画。

帧动画在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用于设定改图片展示的时间,然后在代码中作为背景进行播放

<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>


这里找的是几个录制声音的图片,简单的连起来就是一个录制声音的图像



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值