animation-list,帧动画

本文介绍了一种使用Android平台实现帧动画的方法。通过设置ImageView并利用AnimationDrawable资源,可以创建循环播放的帧动画效果。具体步骤包括定义ImageView、设置背景为动画资源及启动动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中需要实现帧动画的需求,查阅相关资料,将实现的效果进行了整理,内容如下

图片如上,是几张不同的图片,关键代码如下

布局文件中imageview 站位

  <ImageView
        android:id="@+id/iv_dialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
           android:layout_marginLeft="20dp"
           android:visibility="invisible"
         />

public ImageView iv_dialog;

public AnimationDrawable amAnimationDrawable;


iv_dialog=(ImageView)findViewById(R.id.iv_dialog);

iv_dialog.setBackgroundResource(R.anim.progress);

amAnimationDrawable=(AnimationDrawable)iv_dialog.getBackground();

amAnimationDrawable.start();


在res文件夹下建立anim文件夹,里面是progress.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/progress_1" android:duration="200"/>
    <item android:drawable="@drawable/progress_2" android:duration="200"/>
    <item android:drawable="@drawable/progress_3" android:duration="200"/>
    <item android:drawable="@drawable/progress_4" android:duration="200"/>
    <item android:drawable="@drawable/progress_5" android:duration="200"/>
    <item android:drawable="@drawable/progress_6" android:duration="200"/>
    <item android:drawable="@drawable/progress_7" android:duration="200"/>
    <item android:drawable="@drawable/progress_8" android:duration="60"/>

</animation-list>


至此,帧动画的功能实现了





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值