Android的Activity切换有两种方法,
第一种是用代码方式实现:
Activity A跳转到Activity B,要在startActivity(intent)后面加上overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
Activity B返回Activity A,要在finish()后面加上overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
anim_in是进入的Activity的动画,anim_out是退出的Activity的动画。
第二种方法是使用theme实现:(manifest中)
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme"
>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" mce_bogus="1" parent="@android:style/Theme.Light">
<item name="android:windowAnimationStyle">@style/default_animation</item>
<item name="android:windowNoTitle">true</item>
</style> <!-- 默认Activity跳转动画 -->
<style name="default_animation" mce_bogus="1" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/default_anim_in</item>
<item name="android:activityOpenExitAnimation">@anim/anim_stay</item>
<item name="android:activityCloseEnterAnimation">@anim/anim_stay</item>
<item name="android:activityCloseExitAnimation">@anim/default_anim_out</item>
</style>
</resources>
然后就是在res/anim文件夹中定义对应的动画文件default_anim_in,anim_stay, default_anim_out。
4个item分别代表
Activity A跳转到Activity B时Activity B进入动画;
Activity A跳转到Activity B时Activity A退出动画;
Activity B返回Activity A时Activity A的进入动画
Activity B返回Activity A时ActivityB的退出动画
anim_stay.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="4000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="0"/>
</set>
default_anim_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="1600"
android:fromXScale="0.7"
android:fromYScale="0.7"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1"/> <alpha
android:duration="1600"
android:fromAlpha="0"
android:toAlpha="1.0"/>
</set>
default_anim_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"> <scale
android:duration="1600"
android:fromXScale="1"
android:fromYScale="1"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.7"
android:toYScale="0.7" /> <alpha
android:duration="1600"
android:fromAlpha="1"
android:toAlpha="0" /> </set>
文章参考:http://www.open-open.com/lib/view/open1374294856931.html