Android Animation 之 Drawable Animation(帧动画)

一、简介

       帧动画是一个接一个地加载一系列Drawable资源来创建一个动画。这是一种传统的动画,它是利用一系列不同的图像按顺序播放来实现一个动画,就像一卷胶卷。

二、详解

1.常用属性介绍

  animationDrawable.start();//动画开始。
  animationDrawable.setOneShot(true);//设置动画是否只播放一次。
  animationDrawable.stop();//动画停止。
  animationDrawable.isRunning();//返回动画是否正在运行。
  animationDrawable.addFrame(getResources().getDrawable(R.drawable.explode_1), 80);//通过代码添加帧

三、示例

1.Java代码实现

  imageView1 = (ImageView) findViewById(R.id.imageView1);
  imageView1.setBackgroundResource(R.drawable.explode_anim);
  AnimationDrawable animationDrawable = (AnimationDrawable) imageView1.getBackground();
  animationDrawable.start();

2.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/explode_1"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_2"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_3"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_4"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_5"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_6"
        android:duration="80"></item>
    <item
        android:drawable="@drawable/explode_7"
        android:duration="80"></item>
</animation-list>

3.示例效果

4.示例代码下载地址

      github地址 https://github.com/Ya-Jun/SmallSampleCollection

四、文档

      文档本地查看路径

      file:///D:/Android/android-sdk-windows/docs/guide/topics/graphics/drawable-animation.html

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ya-Jun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值