Android动画笔记之Animation

版权声明:本文为博主原创文章,未经博主允许不得转载: https://blog.csdn.net/sinat_33381791/article/details/82902283

简介

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相关动画信息。

猜你喜欢

转载自blog.csdn.net/sinat_33381791/article/details/82902283