老式電視機關閉的時候畫面一閃消失的那個效果:
首先創建一個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; @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); } } }
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() { @Override public void onClick(View v) { img.startAnimation(new TVOffAnimation()); } });
http://www.cnblogs.com/mudoot/articles/1985142.html
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
