zoukankan      html  css  js  c++  java
  • Android电视关闭的闪屏动画效果

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

     

     

    首先创建一个TVOffAnimation继承于Animation: 

    首先创建一个TVOffAnimation继承于Animation

     然后在initialize里面设置一些参数
    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;

    @Override
    public 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());

    }

    @Override
    protected 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);
    }
    }
    }


    说明一下做法:

    其中setInterpolator(new AccelerateDecelerateInterpolator())选择一个先加速后减速的效果

    最后动画的部分里面

    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个值比较疑惑,其实很简单,这是一个一次函数的函数值
    如图为sx的变化曲线
     
    然后在activity中直接可以用了 :
    View img = findViewById(R.id.imageView);
    button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    img.startAnimation(new TVOffAnimation());
    }
    });

    /Files/mudoot/TVOffDemo.rar 

  • 相关阅读:
    学习 CosmosDB (NoSql)
    <linux-sed> sed基本用法
    grep 正则表达式用引号括起来和元字符加反斜杠转义的测试
    CACTI批量添加linux主机sh脚本
    一个简单的C共享库的创建及Python调用此库的方法
    Linux下的C的开发之GCC的初级使用
    AcitveReocrd事件和关联操作
    Samrty技术的 初步了解
    Ubuntu下配置Tomcat
    在ubuntu中安装jdk
  • 原文地址:https://www.cnblogs.com/shanzei/p/2415664.html
Copyright © 2011-2022 走看看