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





首先创建一个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 View的background何时加载的
  2. [Android]Delphi/C++ Builder 开发 Andro
  3. Android UI绘制之View重绘
  4. Android(安卓)Studio 调试 AnnotationPro
  5. android开机启动时间优化:系统初步评估
  6. android开发之PreferenceScreen使用详解
  7. 在Android下创建文件夹
  8. Android Jetpack架构组件之Navigation
  9. Android新手上路----用短信自动回复来电
  10. Android Studio 构建那些事