Android电视关闭的动画效果


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

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

  1. import Android.graphics.Matrix;  
  2. import android.view.animation.AccelerateDecelerateInterpolator;  
  3. import android.view.animation.Animation;  
  4. import android.view.animation.Transformation;  
  5.   
  6. public class TVOffAnimation extends Animation {  
  7.   
  8.     private int halfWidth;  
  9.     private int halfHeight;  
  10.   
  11.     @Override  
  12.     public void initialize(int width, int height, int parentWidth,  
  13.             int parentHeight) {  
  14.   
  15.         super.initialize(width, height, parentWidth, parentHeight);  
  16.         setDuration(500);  
  17.         setFillAfter(true);  
  18.         //保存View的中心点  
  19.         halfWidth = width / 2;  
  20.         halfHeight = height / 2;  
  21.         setInterpolator(new AccelerateDecelerateInterpolator());  
  22.           
  23.     }  
  24.   
  25.     @Override  
  26.     protected void applyTransformation(float interpolatedTime, Transformation t) {  
  27.   
  28.         final Matrix matrix = t.getMatrix();  
  29.         if (interpolatedTime < 0.8) {  
  30.             matrix.preScale(1+0.625f*interpolatedTime, 1-interpolatedTime/0.8f+0.01f,halfWidth,halfHeight);  
  31.         }else{  
  32.             matrix.preScale(7.5f*(1-interpolatedTime),0.01f,halfWidth,halfHeight);  
  33.         }  
  34.     }  
  35. }  
  • 1
  • 2
  • 下一页

相关内容