android 动画<二>

android帧动画

上一篇主要总结了android的Tween动画,这篇主要总结Frame动画。

步骤

1 一组类似的图片,这可能需要美工的设计。
2 写一个包含animation-list的xml文件(很多人说是在drawable或者anim的文件夹下都可以,但是我在studio中试过之后发现animation-lis标签报错,移到drawable文件夹下就正常了。)
3 在代码中把动画的xml文件当做普通的图片资源就可以,具体写法如下。

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/iv_user_icon" android:duration="50"/>
    <item android:drawable="@drawable/iv_user_icon1" android:duration="50"/>
    <item android:drawable="@drawable/iv_user_icon2" android:duration="50"/>
    <item android:drawable="@drawable/iv_user_icon3" android:duration="50"/>
    <item android:drawable="@drawable/iv_user_icon0" android:duration="50"/>

</animation-list>

注:在animation-list的标签中 android:oneshot=”true” 这个属性要值得注意,当值为true时动画走一次就停止了,如果值为false动画会持续。

代码中:

 1  mImage.setBackgroundResource(R.drawable.anim);
 2    AnimationDrawable animationDrawable = (AnimationDrawable)mImage.getBackground();
 3  animationDrawable.start();
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值