活动过渡效果:滑入顶部活动并缩放底部活动

时间:2016-03-19 17:05:19

标签: android xml animation

我想达到下面显示的效果。效果来自Facebook。

effect

我在活动A

中试过这个
    overridePendingTransition(R.anim.anim_left_to_right, R.anim.scale_out);

活动B

  overridePendingTransition(R.anim.anim_right_to_left, R.anim.scale_in);

xml显示在下面:

R.anim.anim_left_to_right

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate android:fromXDelta="100%" 
        android:toXDelta="0%"
        android:fromYDelta="0%" 
        android:toYDelta="0%"
        android:duration="300"/>
</set>

R.anim.anim_right_to_left

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:fromXDelta="0%" android:toXDelta="100%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="300" />
</set>

R.anim.scale_out

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:toXScale="1.0"
            android:toYScale="1.0"
            android:duration="500"
            android:fillBefore="false" />
</set>

R.anim.scale_in

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:toXScale="0.8"
            android:toYScale="0.8"
            android:duration="500"
            android:fillBefore="false" />
</set>

然而,它没有达到预期的效果 - 出于某种原因,我可能无法做到这一点。有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:7)

Slower Faster

样式:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ....
    <item name="android:windowAnimationStyle">@style/ActivityAnimation</item>
</style>

<style name="ActivityAnimation" parent="@android:style/Animation">
    <item name="android:activityOpenEnterAnimation">@anim/activity_in</item>
    <item name="android:activityOpenExitAnimation">@anim/activity_out</item>
    <item name="android:activityCloseEnterAnimation">@anim/activity_back_in</item>
    <item name="android:activityCloseExitAnimation">@anim/activity_back_out</item>
</style>

<强> activity_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0%p"
        android:duration="@integer/activityAnimationTime">
    </translate>
</set>

<强> activity_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="1.0"
        android:toXScale="0.84"
        android:fromYScale="1.0"
        android:toYScale="0.84"
        android:duration="@integer/activityAnimationTime"/>
    <translate
        android:fromYDelta="0%"
        android:fromXDelta="0%"
        android:toYDelta="8%"
        android:toXDelta="16%"
        android:duration="@integer/activityAnimationTime"/>

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.25"
        android:duration="@integer/activityAnimationTime"/>

</set>

<强> activity_back_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:fromXScale="0.84"
        android:toXScale="1.0"
        android:fromYScale="0.84"
        android:toYScale="1.0"
        android:duration="@integer/activityAnimationTime"/>
    <translate
        android:fromYDelta="8%"
        android:fromXDelta="16%"
        android:toYDelta="0%"
        android:toXDelta="0%"
        android:duration="@integer/activityAnimationTime"/>

    <alpha
        android:fromAlpha="0.25"
        android:toAlpha="1.0"
        android:duration="@integer/activityAnimationTime"/>

</set>

<强> activity_back_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0%p"
        android:toXDelta="100%p"
        android:duration="@integer/activityAnimationTime">
    </translate>
</set>