Android电视关闭的闪屏动画效果
生活随笔
收集整理的這篇文章主要介紹了
Android电视关闭的闪屏动画效果
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
老式電視機關(guān)閉的時候畫面一閃消失的那個效果:?
?
?
首先創(chuàng)建一個TVOffAnimation繼承于Animation:?
首先創(chuàng)建一個TVOffAnimation繼承于Animation
然后在initialize里面設(shè)置一些參數(shù) 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表示的是當(dāng)前動畫的間隔時間 范圍是0-1
那么橫向來講前80%的時間我們要橫向拉伸到150%,縱向是直接減小,最后只留一條線。 后20%的時間里我們要橫向從150%壓縮至0%,縱向保持不變就好了,當(dāng)橫向為0的時候就全部消失了。 可能大家對于1+0.625f*interpolatedTime, 1-interpolatedTime/0.8f+0.01f,7.5f*(1-interpolatedTime),0.01f 這4個值比較疑惑,其實很簡單,這是一個一次函數(shù)的函數(shù)值 如圖為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?
?
轉(zhuǎn)自:http://www.cnblogs.com/mudoot/articles/1985142.html轉(zhuǎn)載于:https://www.cnblogs.com/shanzei/archive/2012/03/24/2415664.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Android电视关闭的闪屏动画效果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何解决Maven导入Oracle驱动出
- 下一篇: xposed框架定位修改怎么用_Andr