首页 > 其他 > 详细

仿电视关机效果的动画

时间:2015-03-27 15:00:45      阅读:192      评论:0      收藏:0      [点我收藏+]

仿电视关机效果的动画


  • 效果图

技术分享

  • 主要代码
package com.zhengsonglan.tvanimation;

import android.graphics.Matrix;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
 * Created by zsl on 2015/3/27.
 */
public class TVOffAnimation extends Animation {
    int halfWidth;
    int halfHeight;

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        //设置动画时间为700毫秒
        setDuration(700);
        //设置动画结束后就结束在动画结束的时刻
        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();
        //interpolatedTime是从0~1的一个变化,所以我们前80%让动画缩小成一个线,后20%保持线的高度缩小线的宽度
        if (interpolatedTime<0.8){
            matrix.preScale(1+0.625f*interpolatedTime,1-interpolatedTime/0.8f+0.01f,halfWidth,halfHeight);
        }else{
            matrix.setScale(7.5f*(1-interpolatedTime),0.01f,halfWidth,halfHeight);
        }

    }
}
  • github地址

点击这里,欢迎Star

仿电视关机效果的动画

原文:http://blog.csdn.net/yy1300326388/article/details/44674219

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!