学习笔记---------安卓动画

一、帧动画

  1. 帧动画就是一堆图片的集合
  2. 首先new一个资源文件在这里插入图片描述
  3. 然后添加动画集合(图片不能太大不然不能成功加载)属性值为animation-list。
    在这里插入图片描述
  4. 然后在控件中设置动画背景
  5. 在活动中获取控件背景(start和stop分别控制动画启动和停止)在这里插入图片描述
  6. 效果如图所示:在这里插入图片描述

二、补间动画

  1. 补间动画有四个操作属性:分别是透明度(alpha)、缩放(scale)、平移(translate)、旋转(rotate);
    这些操作属性都要写在xml文件中:
    首先要在res中new一个anim包,然后在包中new所需要的xml文件
    在这里插入图片描述

透明度(alpha)

 <?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="1.0"
    android:toAlpha="0.1"
    android:duration="2000"/>

在这里插入图片描述
缩放(scale)

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="0"
    android:toXScale="2.0"
    android:fromYScale="1.0"
    android:toYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="2000"/>

在这里插入图片描述
平移(translate)
这里有个小bug,如果命名空间没写对不会报错,但是duration属性会无效

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:toXDelta="320"
    android:toYDelta="0" />

在这里插入图片描述
旋转(rotate)

<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotY="50%"
    android:pivotX="10%"
    android:duration="2000"/>

在这里插入图片描述
组合(要用set属性框起来)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromAlpha="1.0"
        android:toAlpha="0.1"
        android:duration="2000"/>
    <rotate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotY="50%"
        android:pivotX="10%"
        android:duration="2000"/>
    <scale xmlns="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXScale="0"
        android:toXScale="2.0"
        android:fromYScale="1.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"/>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="2000"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toXDelta="320"
        android:toYDelta="0" />
</set>
  1. 要使控件动起来只需要用 animationUtils这个动画工具类去调用它的函数loadanimation,从而获取到一个Animation对象,再用控件对象去启动动画把他传参进去。
 Animation loadAnimation = AnimationUtils.loadAnimation(context, xml);
 imageView.startAnimation(loadAnimation);
  1. 展示图片
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

三、属性动画(直接通过代码去设置控件动画效果)

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值