老式电视机关闭的时候画面一闪消失的那个效果:





首先创建一个TVOffAnimation继承于Animation:
import android.graphics.Matrix;import android.view.animation.AccelerateDecelerateInterpolator;import android.view.animation.Animation;import android.view.animation.Transformation;public class TVOffAnimation extends Animation {private int halfWidth;private int halfHeight;@Overridepublic void initialize(int width, int height, int parentWidth,int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);setDuration(500);setFillAfter(true);//保存View的中心点halfWidth = width / 2;halfHeight = height / 2;setInterpolator(new AccelerateDecelerateInterpolator());}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {final Matrix matrix = t.getMatrix();if (interpolatedTime < 0.8) {matrix.preScale(1+0.625f*interpolatedTime, 1-interpolatedTime/0.8f+0.01f,halfWidth,halfHeight);}else{matrix.preScale(7.5f*(1-interpolatedTime),0.01f,halfWidth,halfHeight);}}}


interpolatedTime表示的是当前动画的间隔时间 范围是0-1

那么横向来讲前80%的时间我们要横向拉伸到150%,纵向是直接减小,最后只留一条线。
后20%的时间里我们要横向从150%压缩至0%,纵向保持不变就好了,当横向为0的时候就全部消失了。
可能大家对于1+0.625f*interpolatedTime, 1-interpolatedTime/0.8f+0.01f,7.5f*(1-interpolatedTime),0.01f 这4个值比较疑惑,其实很简单,这是一个一次函数的函数值。

然后在activity中直接可以用了
View img = findViewById(R.id.imageView);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {img.startAnimation(new TVOffAnimation());}});


http://www.cnblogs.com/mudoot/articles/1985142.html

更多相关文章

  1. 箭头函数的基础使用
  2. Python技巧匿名函数、回调函数和高阶函数
  3. 浅析android通过jni控制service服务程序的简易流程
  4. Android(安卓)bluetooth介绍(四): a2dp connect流程分析
  5. Android架构分析之使用自定义硬件抽象层(HAL)模块
  6. android style
  7. Android中OpenMax的适配层
  8. android 包管理系统分析
  9. Android中获取屏幕相关信息(屏幕大小,状态栏、标题栏高度)

随机推荐

  1. 多款Android播放器源码集锦
  2. Android(安卓)GridView属性
  3. Android(安卓)SDK源码下载
  4. Android(安卓)SDK版本与API Level对应列
  5. 系统自带的主题与样式(theme and style)
  6. Android常见inputType
  7. Android(安卓)Bitmap最全基本操作:与Drawa
  8. Android系统自带theme
  9. android 相对布局属性
  10. warning: found plain 'id' attribute; d