【Android基础知识】Drawable Animation和View Animation

Android中的动画主要分为三类

1.Drawable Animation

2.View Animation

3.Property Animation

这里介绍其中的两类,Drawable Animation(逐帧动画)和View Animation

Drawable Animation 逐帧播放每一张图片,就好像动画播放一样。

View Animation  包括 平移动画 translate 、缩放动画 scale 、旋转动画 rotate 、渐变动画 alpha

Drawable Animation (逐帧动画)

我们使用 animation-list 来定义动画xml文件,在工程res的anim文件夹或者drawable文件夹下建立我们的动画文件

anim_list.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
<!-- onshot 为true表示只播放一次,false表示循环播放 -->
    <item
        android:drawable="@drawable/one"
        android:duration="500"/>
    <item
        android:drawable="@drawable/two"
        android:duration="500"/>
    <item
        android:drawable="@drawable/three"
        android:duration="500"/>
    <item
        android:drawable="@drawable/four"
        android:duration="500"/>
    <item
        android:drawable="@drawable/five"
        android:duration="500"/>
    <item
        android:drawable="@drawable/six"
        android:duration="500"/>
</animation-list>
使用AnimationDrawable 启动动画,代码如下,调用stop可以停止动画

private AnimationDrawable walkDrawable;
image.setImageResource(R.drawable.anim_list);
			walkDrawable = (AnimationDrawable)image.getDrawable();
			walkDrawable.start();


View Animation

在代码中定义动画这里不做介绍,主要介绍在xml中定义动画
渐变动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration=
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值