Android动画笔记之Animation

简介

Android提供了两种机制,您可以使用它们来创建简单的动画:补间动画,您可以在其中告诉Android对视图内容执行一系列简单的转换(位置,大小,旋转等); 和逐帧动画,一个接一个地加载一系列Drawable资源。 两种动画类型都可以在任何View对象中使用,以提供简单的旋转计时器,活动图标和其他有用的UI元素。 Tweened动画由此包处理(android.view.animation); 逐帧动画由AnimationDrawable类处理。

使用

amin文件夹下的属性

在xml属性有哪些以及他们的用法

属性意图(作用)
alpha透明度渐变效果
scale尺寸伸缩效果
translate移动效果
rotate旋转效果
set全部的集合
  • 注:在res目录下新建一个文件夹命名为anim,然后创建xml文件。

加载使用方式

 Animation animation = AnimationUtils.loadAnimation(this, R.amin.demo);
 button.startAnimation(animation );

插补器Interpolator认识

插补器InterpolatorBaseInterpolator.class是由默认插值器扩展的抽象类。

插补器子类(.class)xml属性引用意图(效果)
AccelerateDecelerateInterpolator@android:anim/accelerate_decelerate_interpolator变化率开始和结束缓慢但在中间加速
AccelerateInterpolator@android:anim/accelerate_interpolator变化率开始缓慢而然后加速
AnticipateInterpolator@android:anim/anticipate_interpolator变化开始向后然后向前飞行
AnticipateOvershootInterpolator@android:anim/anticipate_overshoot_interpolator变化开始向后然后向前飞过并超过目标值,最后返回到最终值
BounceInterpolator@android:anim/bounce_interpolator变化在结束时反弹
CycleInterpolator@android:anim/cycle_interpolator重复动画指定的周期数,变化率遵循正弦曲线模式
DecelerateInterpolator@android:anim/decelerate_interpolator变化率快速开始,然后减速
LinearInterpolator@android:anim/linea_interpolator变化是恒定的方式改变
OvershootInterpolator@android:anim/overshoot_interpolator变化向前晃动并超过最后一个值然后返回
PathInterpolator@android:anim/path_interpolator根据路径的设置来改变

代码自定义创建动画

Animation.class类分析 可应用于视图,曲面或其他对象的动画的抽象基类。它的子类源码结构如下:

动画子类(.class)解释说明构造器
ScaleAnimation控制对象比例的动画。您可以指定用于缩放中心的点ScaleAnimation(Context context, AttributeSet attrs)从资源加载ScaleAnimation时使用的构造方法
下面的都是从代码构建ScaleAnimation时使用的构造器:ScaleAnimation(float fromX, float toX, float fromY, float toY)
ScaleAnimation(float fromX, float toX, float fromY, float toY,float pivotX, float pivotY)
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
AlphaAnimation控制对象alpha级别的动画,用于淡入淡出效果AlphaAnimation(Context context, AttributeSet attrs)从资源加载AlphaAnimation时使用的构造方法。
下面的都是从代码构建AlphaAnimation时使用的构造器:
AlphaAnimation(float fromAlpha, float toAlpha)
RotateAnimation控制对象旋转的动画,该旋转在X-Y平面中占据位置,可以指定用于旋转中心的点,如果未指定,则(0,0)默认旋转点RotateAnimation(Context context, AttributeSet attrs)从资源加载RotateAnimation时使用的构造方法
RotateAnimation(float fromDegrees, float toDegrees)从代码构建RotateAnimation时使用的构造方法,默认的pivotX / pivotY点是(0,0)
RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY); pivotX/pivotY:对象旋转的点的X/Y坐标
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue,int pivotYType, float pivotYValue)
pivotYType/pivotYValue指定Animation类型如:Animation.RELATIVE_TO_SELF
TranslateAnimation控制对象位置的动画,移动效果TranslateAnimation(Context context, AttributeSet attrs):从资源加载TranslateAnimation时使用的构造方法
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)从代码构建TranslateAnimation时使用的构造方法
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,int fromYType, float fromYValue, int toYType, float toYValue)
AnimationSet表示应该一起播放的一组动画(全部动画的集合)AnimationSet(Context context, AttributeSet attrs)
AnimationSet(boolean shareInterpolator)从代码中使用构造函数,如果此设置中的所有动画都应使用与此AnimationSet关联的插值器,则传递true,如果每个动画都应使用自己的插值器,则传递false。

总结

本篇主要简单记录Animation相关动画信息。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值