模擬優(yōu)酷像關(guān)電視一樣的退出效果
其實所謂像關(guān)電視一樣的退出效果就是一個動畫而已,好吧,看到這里的朋友可以先自己想想,其實思路是很簡單的。
1.要求屏幕瞬間白屏。
2.白色屏幕以勻加速或勻減速向中間擠壓,直至一條白線后消失不見,整個過程大概200毫秒。
3.露出黑漆漆一片的黑色背景。
首先,布局文件的寫法。有很多種,最簡單的就是利用RelativeLayout或者FrameLayout為應(yīng)用首界面的根布局,如果應(yīng)用的背景色本身為黑色最好,就像優(yōu)酷一樣。如果應(yīng)用的背景色不為黑色,那么在根布局里寫一:
- <FrameLayout
- android:id="@+id/fl_off"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:visibility="gone"
- >
- <ImageView
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@color/text_black" />
- <ImageView
- android:id="@+id/iv_off"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@color/text_white"
- android:visibility="gone"/>
- </FrameLayout>
第一個ImageView為黑色的背景色,第二個為白色的背景色。
下面是動畫文件的寫法 res/anim/tv_off.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <set android:shareInterpolator="false"
- android:zAdjustment="top"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <span></span>
- <scale android:interpolator="@android:anim/accelerate_interpolator"
- android:duration="200"
- android:pivotX="50.0%"
- android:pivotY="50.0%"
- android:fromXScale="1.0"
- android:toXScale="1.0"
- android:fromYScale="1.0"
- android:toYScale="0.0030" />
- <scale android:interpolator="@android:anim/accelerate_interpolator"
- android:duration="200"
- android:pivotX="50.0%"
- android:pivotY="50.0%"
- android:startOffset="200"
- android:fromXScale="1.0"
- android:toXScale="0.0"
- android:fromYScale="1.0"
- android:toYScale="0.3" />
- <alpha android:interpolator="@interpolator/accelerate_quint"
- android:duration="400"
- android:fillAfter="true"
- android:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:fillEnabled="true" />
- </set>
這個很簡單,大家copy就行了。
因為動畫引用到了加速器,下面是加速器文件的寫法 res/interpolator/accelerate_quint.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <accelerateInterpolator android:factor="2.5"
- xmlns:android="http://schemas.android.com/apk/res/android" />
這是一個勻加速的加速器,加速倍數(shù)為2.5。