效果
新进入的页面从右边滑入,当前页面从左边滑出,按下返回键的时候,当前页面从右边滑出,前一个页面从左边滑入。
设置主题
1.style文件配置:
<style name="activityAnimation" parent="@android:style/Animation">
<item name="android:activityOpenEnterAnimation">@anim/anim_window_in</item>
<item name="android:activityOpenExitAnimation">@anim/anim_window_out</item>
<item name="android:activityCloseEnterAnimation">@anim/anim_window_close_in</item>
<item name="android:activityCloseExitAnimation">@anim/anim_window_close_out</item>
</style>
2. 主题配置:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/activityAnimation</item>
</style>
3.应用:
动画anim
- anim_interpolator
<?xml version="1.0" encoding="utf-8"?>
<decelerateInterpolator android:factor="2.5"
xmlns:android="http://schemas.android.com/apk/res/android" />
- anim_window_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"
android:interpolator="@anim/anim_interpolator"
android:shareInterpolator="true"
android:zAdjustment="top">
<translate
android:duration="@integer/anim_speed"
android:fromXDelta="100.0%p"
android:toXDelta="0.0%p" />
</set>
- anim_window_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"
android:interpolator="@anim/anim_interpolator"
android:shareInterpolator="true"
android:zAdjustment="normal">
<translate
android:duration="@integer/anim_speed"
android:fromXDelta="0.0%p"
android:toXDelta="-29.999996%p" />
<alpha
android:duration="@integer/anim_speed"
android:fromAlpha="1.0"
android:toAlpha="0.6" />
<scale
android:duration="@integer/anim_speed"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50.0%p"
android:pivotY="50.0%p"
android:toXScale="0.92"
android:toYScale="0.92" />
</set>
- anim_window_close_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"
android:interpolator="@anim/anim_interpolator"
android:shareInterpolator="true"
android:zAdjustment="normal">
<translate
android:duration="@integer/anim_speed"
android:fromXDelta="-29.999996%p"
android:toXDelta="0.0%p" />
<alpha
android:duration="@integer/anim_speed"
android:fromAlpha="0.4"
android:toAlpha="1.0" />
<scale
android:duration="@integer/anim_speed"
android:fromXScale="0.92"
android:fromYScale="0.92"
android:pivotX="50.0%p"
android:pivotY="50.0%p"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
- anim_window_close_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"
android:interpolator="@anim/anim_interpolator"
android:shareInterpolator="true"
android:zAdjustment="bottom">
<translate
android:duration="@integer/anim_speed"
android:fillAfter="true"
android:fillBefore="true"
android:fillEnabled="true"
android:fromXDelta="0.0%p"
android:toXDelta="100.0%p" />
</set>
按照这样写完%……&%&%……&,实现效果了吗?确实实现了;but,在activity finish的时候的确没有任何问题,而在跳转下一Activity时会出现短暂的黑屏(黑屏时间视下一activity绘制时间而定),这时,在 style中的 activityAnimation 中添加
<item name="android:windowIsTranslucent">true</item>
(设置半透明)