3

我检查了 API 代码附带的过渡动画,我发现动画 zoom_enter 和 zoom_exit 在其中活动 1 下沉以显示活动 2。我需要相反的方式。我需要活动 2 从内部缩小并到达顶部。(我希望你能得到我)。这种类型的动画在 iphone 屏幕转换上是相同的。

下面的代码是我不需要的效果。这是 zoom_enter.xml 的代码

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="2.0" android:toXScale="1.0"
       android:fromYScale="2.0" android:toYScale="1.0"
       android:pivotX="50%p" android:pivotY="50%p"
       android:duration="@android:integer/config_mediumAnimTime" />
</set>

这是 zoom_exit.xml 的代码

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:zAdjustment="top">
    <scale android:fromXScale="1.0" android:toXScale=".5"
       android:fromYScale="1.0" android:toYScale=".5"
       android:pivotX="50%p" android:pivotY="50%p"
       android:duration="@android:integer/config_mediumAnimTime" />
    <alpha android:fromAlpha="1.0" android:toAlpha="0"
        android:duration="@android:integer/config_mediumAnimTime"/>
</set>

然后在 startActivity 之后我调用下面的方法:

 overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);

谁能建议我如何更改上述文件以使我解释的屏幕转换?

4

2 回答 2

13

在 zoom_enter.xml 中尝试此操作并从 zoom_exit.xml 中删除动画。你会看到更好的效果。

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="0.0" android:toXScale="1.0"
       android:fromYScale="0.0" android:toYScale="1.0"
       android:pivotX="50%p" android:pivotY="50%p"
       android:duration="@android:integer/config_mediumAnimTime" />
</set>

希望这可以帮助。

于 2013-02-12T12:20:21.363 回答
2

overridePendingTransition(zoom_enter_new, zoom_exit_actual);

第一个参数用于传入的活动(所以是新的)第二个参数是用于传出的活动(实际的)

因此,如果您想制作与视频相同的效果,其中实际活动似乎立即隐藏,而不是第二个参数需要设置为 0(意味着没有动画)

overridePendingTransition(zoom_enter_new, 0);

为了使新活动像视频一样放大,这是解释的动画 xml 资源(res/anim/ dir 中的 zoom_enter_new.xml)

    <set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <!--scale view fromX fromY are the starting point  (.5 is 50% of scale, )-->
    <!--scale view toX and toY are the final state (1 is 100%)-->
    <!--pivot is the center of animation, so in your case the zoomin on the video is from the exact center (50% pivot x, 50% pivot Y)-->
    <scale android:fromXScale=".5" android:toXScale="1"
        android:fromYScale=".5" android:toYScale="1"
        android:pivotX="50%p" android:pivotY="50%p"
        android:duration="@android:integer/config_longAnimTime" />

    <!-- alpha animation is made at the same time of scale animation, and for me make a better and smooth result, alpha 0 is full trasparent, 1 is the normal state. The final alpha state of the activity after this animation is 1, so pay attention toAlpha must be 1 if you don't want glitch-->
    <alpha android:fromAlpha="0.5" android:toAlpha="1"
        android:duration="@android:integer/config_longAnimTime"/>
</set>

overridePendingTransition(R.anim.zoom_enter_new, 0);

托比亚

于 2017-05-16T09:07:26.900 回答