电视机关机特效——android

yu-Sniper

Read The Fucking Source Code || 雄关漫道真如铁,而今迈步从头越

Android-模拟电视屏幕开关机特效

效果图:

电视机关机特效——android


布局代码:

activity_main.xml

[java] view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#000000"  
  6.     tools:context=".MainActivity">  
  7. <LinearLayout  
  8.     android:id="@+id/LL"  
  9.     android:layout_width="wrap_content"  
  10.     android:orientation="horizontal"  
  11.     android:layout_centerHorizontal="true"  
  12.     android:layout_height="wrap_content">  
  13.     <Button  
  14.         android:background="#ffffff"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:onClick="off"  
  18.         android:text="关" />  
  19.   
  20.     <Button  
  21.         android:background="#ffffff"  
  22.         android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:onClick="on"  
  25.         android:text="开" />  
  26. </LinearLayout>  
  27.     <LinearLayout  
  28.         android:layout_below="@+id/LL"  
  29.         android:layout_width="match_parent"  
  30.         android:layout_height="match_parent">  
  31.     <ImageView  
  32.   
  33.         android:layout_width="match_parent"  
  34.         android:layout_height="match_parent"  
  35.         android:id="@+id/imageView"  
  36.         android:scaleType="centerCrop"  
  37.         android:src="@drawable/aa"/>  
  38.     </LinearLayout>  
  39. </RelativeLayout>  

MyAnimation.java

[java] view plain copy
  1. package com.example.yu_longji.android21;  
  2.   
  3. import android.graphics.Matrix;  
  4. import android.view.animation.AccelerateDecelerateInterpolator;  
  5. import android.view.animation.AccelerateInterpolator;  
  6. import android.view.animation.Animation;  
  7. import android.view.animation.Transformation;  
  8.   
  9. /** 
  10.  * Created by yu_longji on 2015/8/30. 
  11.  */  
  12. public class MyAnimation {  
  13.   
  14.     OffAnimation offanim;  
  15.     OnAnimation onanim;  
  16.   
  17.     MyAnimation() {  
  18.         offanim = new OffAnimation();  
  19.         onanim = new OnAnimation();  
  20.     }  
  21.   
  22.   
  23.     public class OffAnimation extends Animation {  
  24.         int halfWidth;  
  25.         int halfHeight;  
  26.   
  27.         @Override  
  28.         public void initialize(int width, int height, int parentWidth, int parentHeight) {  
  29.             super.initialize(width, height, parentWidth, parentHeight);  
  30.             //设置动画时间为800毫秒  
  31.             setDuration(800);  
  32.             //设置动画结束后就结束在动画结束的时刻  
  33.             setFillAfter(true);  
  34.             //保存View的中心点  
  35.             halfWidth = width / 2;  
  36.             halfHeight = height / 2;  
  37.   
  38.             //设置动画先加速后减速  
  39.   
  40.             setInterpolator(new AccelerateDecelerateInterpolator());  
  41.         }  
  42.   
  43.         @Override  
  44.         protected void applyTransformation(float interpolatedTime, Transformation t) {  
  45.             super.applyTransformation(interpolatedTime, t);  
  46.             final Matrix matrix = t.getMatrix();  
  47.             //interpolatedTime是从0~1的一个变化,所以我们前80%让动画缩小成一个线,后20%保持线的高度缩小线的宽度  
  48.             if (interpolatedTime < 0.8) {  
  49.                 matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.01f, halfWidth, halfHeight);  
  50.             } else {  
  51.                 matrix.setScale(7.5f * (1 - interpolatedTime), 0.01f, halfWidth, halfHeight);  
  52.             }  
  53.         }  
  54.     }  
  55.   
  56.   
  57.     public class OnAnimation extends Animation {  
  58.         int halfWidth;  
  59.         int halfHeight;  
  60.   
  61.         @Override  
  62.         public void initialize(int width, int height, int parentWidth, int parentHeight) {  
  63.             super.initialize(width, height, parentWidth, parentHeight);  
  64.   
  65.             //设置动画时间为900毫秒  
  66.             setDuration(900);  
  67.             //设置动画结束后就结束在动画结束的时刻  
  68.             setFillAfter(true);  
  69.             //保存View的中心点  
  70.             halfWidth = width / 2;  
  71.             halfHeight = height / 2;  
  72.   
  73.             setInterpolator(new AccelerateInterpolator());  
  74.         }  
  75.   
  76.         @Override  
  77.         protected void applyTransformation(float interpolatedTime, Transformation t) {  
  78.             super.applyTransformation(interpolatedTime, t);  
  79.             final Matrix matrix = t.getMatrix();  
  80.             if (interpolatedTime < 0.2) {  
  81.                 matrix.setScale(0.01f, interpolatedTime * 5.0f, halfWidth, halfHeight);  
  82.             } else {  
  83.                 matrix.setScale((float) Math.pow(interpolatedTime, 4), 1, halfWidth, halfHeight * 2);  
  84.             }  
  85.         }  
  86.     }  
  87.   
  88.     //上下收缩  
  89. //        matrix.preScale(1,1-interpolatedTime,halfWidth*2,halfHeight);  
  90.     //中间一条线拉伸  
  91. //        matrix.setScale(interpolatedTime,0.01f,halfWidth,halfHeight);  
  92.     //上下伸展开  
  93. //        matrix.preScale(1,-(interpolatedTime),halfWidth*2,halfHeight);  
  94.     //左右向中间收缩  
  95. //        matrix.preScale(1-interpolatedTime,1,halfWidth,halfHeight*2);  
  96.     //上下伸展开  
  97. //        matrix.setScale(1, interpolatedTime, width, halfHeight);  
  98. }  


MainActivity.java

[java] view plain copy
  1. package com.example.yu_longji.android21;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.ImageView;  
  7.   
  8. public class MainActivity extends Activity {  
  9.   
  10.     ImageView imageView;  
  11.     MyAnimation myAnimation;  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_main);  
  17.         imageView = (ImageView) findViewById(R.id.imageView);  
  18.         myAnimation = new MyAnimation();  
  19.     }  
  20.     //关  
  21.     public void off(View view) {  
  22.         imageView.startAnimation(myAnimation.offanim);  
  23.     }  
  24.     //开  
  25.     public void on(View view) {  
  26.         imageView.startAnimation(myAnimation.onanim);  
  27.     }  
  28.   
  29. }  



个人分类: Android-Demo
电视机关机特效——android

unity5.6 老电视屏幕效果

2017年08月17日 7.19MB 下载

电视机关机特效——android
您有一张免费的北京车展门票等待领取美好购车节 · 顶新
打印机出租,新机销售,选弘顺瑞通,绿色节能办公的首选!弘顺瑞通 · 顶新

模拟google搜索特效

2011年06月08日 2.02MB 下载

电视机关机特效——android

Android-导航栏特效-文字缩放-颜色渐变

2015年03月29日 3.14MB 下载

电视机关机特效——android

Android-编程权威指南

2018年01月23日 14.79MB 下载

电视机关机特效——android

js 特效 html 特效 模拟下雪景象

2011年08月20日 9KB 下载

电视机关机特效——android

js 特效 html 特效 模拟太空飞行

2011年08月20日 11KB 下载

电视机关机特效——android

js 特效 html 特效 模拟跳舞游戏

2011年08月20日 12KB 下载

电视机关机特效——android

个人资料

原创
122
粉丝
29
喜欢
2
评论
27
等级:
访问:
18万+
积分:
2910
排名:
1万+

互动交流

我的邮箱:


[email protected]


Github:


https://github.com/yuSniper


觉得文章哪里有错或是不妥的地方,恳请大家多多指正。如果博文对你有些帮助,请留个脚印,谢谢。 

转载必须注明出处。

最新评论

效果图:

电视机关机特效——android


布局代码:

activity_main.xml

[java] view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#000000"  
  6.     tools:context=".MainActivity">  
  7. <LinearLayout  
  8.     android:id="@+id/LL"  
  9.     android:layout_width="wrap_content"  
  10.     android:orientation="horizontal"  
  11.     android:layout_centerHorizontal="true"  
  12.     android:layout_height="wrap_content">  
  13.     <Button  
  14.         android:background="#ffffff"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:onClick="off"  
  18.         android:text="关" />  
  19.   
  20.     <Button  
  21.         android:background="#ffffff"  
  22.         android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:onClick="on"  
  25.         android:text="开" />  
  26. </LinearLayout>  
  27.     <LinearLayout  
  28.         android:layout_below="@+id/LL"  
  29.         android:layout_width="match_parent"  
  30.         android:layout_height="match_parent">  
  31.     <ImageView  
  32.   
  33.         android:layout_width="match_parent"  
  34.         android:layout_height="match_parent"  
  35.         android:id="@+id/imageView"  
  36.         android:scaleType="centerCrop"  
  37.         android:src="@drawable/aa"/>  
  38.     </LinearLayout>  
  39. </RelativeLayout>  

MyAnimation.java

[java] view plain copy
  1. package com.example.yu_longji.android21;  
  2.   
  3. import android.graphics.Matrix;  
  4. import android.view.animation.AccelerateDecelerateInterpolator;  
  5. import android.view.animation.AccelerateInterpolator;  
  6. import android.view.animation.Animation;  
  7. import android.view.animation.Transformation;  
  8.   
  9. /** 
  10.  * Created by yu_longji on 2015/8/30. 
  11.  */  
  12. public class MyAnimation {  
  13.   
  14.     OffAnimation offanim;  
  15.     OnAnimation onanim;  
  16.   
  17.     MyAnimation() {  
  18.         offanim = new OffAnimation();  
  19.         onanim = new OnAnimation();  
  20.     }  
  21.   
  22.   
  23.     public class OffAnimation extends Animation {  
  24.         int halfWidth;  
  25.         int halfHeight;  
  26.   
  27.         @Override  
  28.         public void initialize(int width, int height, int parentWidth, int parentHeight) {  
  29.             super.initialize(width, height, parentWidth, parentHeight);  
  30.             //设置动画时间为800毫秒  
  31.             setDuration(800);  
  32.             //设置动画结束后就结束在动画结束的时刻  
  33.             setFillAfter(true);  
  34.             //保存View的中心点  
  35.             halfWidth = width / 2;  
  36.             halfHeight = height / 2;  
  37.   
  38.             //设置动画先加速后减速  
  39.   
  40.             setInterpolator(new AccelerateDecelerateInterpolator());  
  41.         }  
  42.   
  43.         @Override  
  44.         protected void applyTransformation(float interpolatedTime, Transformation t) {  
  45.             super.applyTransformation(interpolatedTime, t);  
  46.             final Matrix matrix = t.getMatrix();  
  47.             //interpolatedTime是从0~1的一个变化,所以我们前80%让动画缩小成一个线,后20%保持线的高度缩小线的宽度  
  48.             if (interpolatedTime < 0.8) {  
  49.                 matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.01f, halfWidth, halfHeight);  
  50.             } else {  
  51.                 matrix.setScale(7.5f * (1 - interpolatedTime), 0.01f, halfWidth, halfHeight);  
  52.             }  
  53.         }  
  54.     }  
  55.   
  56.   
  57.     public class OnAnimation extends Animation {  
  58.         int halfWidth;  
  59.         int halfHeight;  
  60.   
  61.         @Override  
  62.         public void initialize(int width, int height, int parentWidth, int parentHeight) {  
  63.             super.initialize(width, height, parentWidth, parentHeight);  
  64.   
  65.             //设置动画时间为900毫秒  
  66.             setDuration(900);  
  67.             //设置动画结束后就结束在动画结束的时刻  
  68.             setFillAfter(true);  
  69.             //保存View的中心点  
  70.             halfWidth = width / 2;  
  71.             halfHeight = height / 2;  
  72.   
  73.             setInterpolator(new AccelerateInterpolator());  
  74.         }  
  75.   
  76.         @Override  
  77.         protected void applyTransformation(float interpolatedTime, Transformation t) {  
  78.             super.applyTransformation(interpolatedTime, t);  
  79.             final Matrix matrix = t.getMatrix();  
  80.             if (interpolatedTime < 0.2) {  
  81.                 matrix.setScale(0.01f, interpolatedTime * 5.0f, halfWidth, halfHeight);  
  82.             } else {  
  83.                 matrix.setScale((float) Math.pow(interpolatedTime, 4), 1, halfWidth, halfHeight * 2);  
  84.             }  
  85.         }  
  86.     }  
  87.   
  88.     //上下收缩  
  89. //        matrix.preScale(1,1-interpolatedTime,halfWidth*2,halfHeight);  
  90.     //中间一条线拉伸  
  91. //        matrix.setScale(interpolatedTime,0.01f,halfWidth,halfHeight);  
  92.     //上下伸展开  
  93. //        matrix.preScale(1,-(interpolatedTime),halfWidth*2,halfHeight);  
  94.     //左右向中间收缩  
  95. //        matrix.preScale(1-interpolatedTime,1,halfWidth,halfHeight*2);  
  96.     //上下伸展开  
  97. //        matrix.setScale(1, interpolatedTime, width, halfHeight);  
  98. }  


MainActivity.java

[java] view plain copy
  1. package com.example.yu_longji.android21;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.ImageView;  
  7.   
  8. public class MainActivity extends Activity {  
  9.   
  10.     ImageView imageView;  
  11.     MyAnimation myAnimation;  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_main);  
  17.         imageView = (ImageView) findViewById(R.id.imageView);  
  18.         myAnimation = new MyAnimation();  
  19.     }  
  20.     //关  
  21.     public void off(View view) {  
  22.         imageView.startAnimation(myAnimation.offanim);  
  23.     }  
  24.     //开  
  25.     public void on(View view) {  
  26.         imageView.startAnimation(myAnimation.onanim);  
  27.     }  
  28.   
  29. }