Android电视关闭的动画效果
16lz
2022-07-25
老式电视机关闭的时候画面一闪消失的那个效果:
首先创建一个TVOffAnimation继承于Animation:
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中直接可以用了
http://www.cnblogs.com/mudoot/articles/1985142.html
首先创建一个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
更多相关文章
- 箭头函数的基础使用
- Python技巧匿名函数、回调函数和高阶函数
- 浅析android通过jni控制service服务程序的简易流程
- Android(安卓)bluetooth介绍(四): a2dp connect流程分析
- Android架构分析之使用自定义硬件抽象层(HAL)模块
- android style
- Android中OpenMax的适配层
- android 包管理系统分析
- Android中获取屏幕相关信息(屏幕大小,状态栏、标题栏高度)