Android动画总结

/res/anim

Frame

1、原理:逐帧动画

<?xml version="1.0"encoding="utf-8"?>

<animation-listxmlns:android="http://schemas.android.com/apk/res/android"

   android:oneshot="false">

   <item android:drawable="@drawable/girl_1"android:duration="200" />

   <item android:drawable="@drawable/girl_2"android:duration="200" />

</animation-list>

2、使用

XML:android:background="@animator/frame"

代码:iv.setBackgroundResource(R.animator.frame);

 

(AnimationDrawable)iv.getBackground().start().stop();// 不能在OnCreate()中启动、停止,因为在OnCreate()中AnimationDrawable还没有完全的与ImageView绑定,在OnCreate()中启动动画,就只能看到第一张图片。

 

Tween

1、原理:补间动画,由

1)Transformation = 仿射矩阵Matrix + alpha值

Defines thetransformation to be applied at one point in time of an Animation.

每种动画变换都是一次快速的矩阵运算:当调用 Canvas.drawBitmap (bmp, x, y, Paint) 绘制之前,View的bmp与这个Transformation的仿射矩阵相乘,然后将运算的结果显示在 Canvas 上,就可实现相应的操作(旋转、平移、缩放等)

所以动画的实质就是不停的修改 Canvas 的矩阵并刷新屏幕

 

2)Interpolator 是基类定义了动画的变化速度,它只有一个方法,即 getInterpolation (float input) 该方法 maps a point on the timeline to a multiplier to be applied to thetransformations of an animation可以实现匀速、正加速、负加速、无规则变加速等

Accelerate加速      Decelerate减速

LinearInterpolator                       匀速

AccelerateInterpolator                  加速

DecelerateInterpolator                  减速

AccelerateDecelerateInterpolator   开始慢——中间加速 —— 结束慢

CycleInterpolator                        速率改变沿着正弦曲线

 

2、使用:

AnimationSet animationSet=new AnimationSet(true);

Animation animation = null;

animation = AnimationUtils.loadAnimation(this, R.anim.alpha); // (1)XML加载

<android:fillEnabled=”true”      android:fillAfter=”true”> 需要设置在set里面

Rotate:顺时针开始,必须防止在最上面

Scale:默认从左上角开始,可以指定prvioX=50% 或使用matrix.preTranslate

animation = new XxxAnimation(x,x,x,x); // (2)编码

animation.setDuration(long durationMills);     // 动画执行的时间,单位是毫秒。

animation.setFillAfter(boolean fillAfter);       // 设为true,则动画完成后停留在结束状态

animation.setFillBefore(boolean fillBefore); // 设为true,则动画完成后停留在初始状态

animation.setStartOffset(long startOffset);  // 动画执行前的等待时间

animation.setRepeatCount(int repeatCount);     // 动画执行重复的次数

animation.setAnimationListener(new AnimationListener());    // 监听

animationSet.addAnimation(alphaAnimation);

view.startAnimation(animationSet);// 给view设置动画

 

LayoutAnimaionController

1、原理:为viewGroup的每个控件都设置相同的动画效果,这些控件的动画效果可以在不同的时间显示出来。viewGroup.getChildCount();

2、使用

XML:/res/anim

<layoutAnimationxmlns:android="http://schemas.android.com/apk/res/android“

   android:delay="0.5" //执行动画的延迟时间,即时间间隔,单位是秒

   android:animationOrder="random"/"normal"/"reverse"  //执行顺序

   android:animation="@anim/***" //这是装载具体动画的xml文件

<ViewGroup android:layoutAnimation="@anim/***" >

代码:

LayoutAnimaionController lac=newLayoutAnimaionController(animation);

lac.setOrder(LayoutAnimaionController .ORDER_NORMAL);      // 设置顺序

lac.setDelay(***f);     // 设置执行动画的延迟时间,即时间间隔,单位是秒

listView.setLayoutAnimation(lac);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值