天天看點

android activity上下切換動畫,Android Activity切換上下抽屜效果

Activity之間的切換效果動畫有很多種,常見的有位移與漸變,縮放用的比較少,旋轉就更不用說了。針對位移來說,是一個Activity出的同時另一個Actvity進,位移還有另一種方式就是抽屜效果,抽屜效果也是位移的一種,但不是一個Activity進另一個Activity出,而是一個Activity覆寫另一個Activty,如下圖所示:

android activity上下切換動畫,Android Activity切換上下抽屜效果
android activity上下切換動畫,Android Activity切換上下抽屜效果

這種效果定義起來就相對麻煩點,下面看下如何來定義:

android:duration="250"

android:fromYDelta="100.0%p"

android:interpolator="@android:anim/decelerate_interpolator"

android:toYDelta="0.0" />

這是一個從下往上的位移動畫從相對父窗體Y軸的100%移動到0,用于Activity的進入

android:duration="250"

android:fromYDelta="0.0%p"

android:interpolator="@android:anim/decelerate_interpolator"

android:toYDelta="100.0%p" />

這是一個從上往下的位移動畫,從相對父窗體的0%移動到100%,用于Activity的退出。

準備了這兩個位移動畫xml檔案後,下面要定義樣式:

@style/PresentAnimation

@anim/slide_up

@anim/slide_down

定義了這兩個動畫樣式後,下面要在AndroidManifest中聲明Activity的時候使用這個樣式:

android:name=".ui.SearchActivity"

android:launchMode="singleTop"

android:theme="@style/Theme.Present"

android:windowSoftInputMode="adjustPan" />

這樣就完成整個位移效果了,當切換Activity的時候就可以看到抽屜效果。

轉載時請注明出處及相應連結,本文永久位址:https://blog.yayuanzi.com/1448.html

android activity上下切換動畫,Android Activity切換上下抽屜效果

微信打賞

支付寶打賞

感謝您對作者wangbin的打賞,我們會更加努力!    如果您想成為作者,請點我