Activity之间的跳转需要一些动画,让画面不要那么尴尬。
下面是一些效果:
- 淡入、淡出
- 左平移入,左平移出
- 右平移入,右平移出
- 缩,放
fade_in.xml代码:
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromAlpha="1.0" android:toAlpha="0.0" >
alpha>
fade_out.xml代码:
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000">
alpha>
left_tran_in.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%" android:toXDelta="0" android:duration="2000" android:fromYDelta="-100%" android:toYDelta="0"/>
set>
left_tran_out.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%" android:duration="2000" android:fromYDelta="0" android:toYDelta="-100%"/>
set>
right_tran_in.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%" android:duration="2000" android:toXDelta="0" />
set>
right_tran_out.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:duration="2000" android:toXDelta="100%" />
set>
scale_in.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="200%" android:toXScale="100%" android:fromYScale="200%" android:toYScale="100%" android:pivotX="50%" android:pivotY="50%" android:duration="2000"/>
<alpha android:fromAlpha="0" android:toAlpha="1" android:duration="2000"/>
set>
scale_out.xml代码:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="100%" android:toXScale="200%" android:fromYScale="100%" android:toYScale="200%" android:pivotX="50%" android:pivotY="50%" android:duration="2000" />
<alpha android:fromAlpha="1" android:toAlpha="0" android:duration="2000"/>
set>
使用overridePendingTransition(int enterAnim, int exitAnim) 实现动画效果,在跳转界面的Intent语句下面加入这一句,并传入动画效果就可以了。
* @param enterAnim A resource ID of the animation resource to use for
* the incoming activity. Use 0 for no animation.
* @param exitAnim A resource ID of the animation resource to use for
* the outgoing activity. Use 0 for no animation.
观察其源码就可以发现,需要传入两个animation resource 给这个方法
第一个是 enterAnim 是对于进入的Activity 的动画效果,第二个是 exitAnim 是对于消失的Activity 的动画效果
由此可见其实可以对于这个overridePendingTransition 其实有多种任意的组合方式,可以做出很多奇奇怪怪的效果。