两个活动之间的缩小过渡动画

4

我查看了API代码中提供的过渡动画,并发现其中有zoom_enter和zoom_exit两种动画效果,其中activity 1会被隐藏进去以展示activity 2。但我需要相反的效果,也就是activity 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);

有人能提供建议,告诉我如何修改上述文件以实现我所描述的屏幕过渡效果吗?

你尝试过颠倒R.anim.zoom_enter和exit吗?有什么问题,你想要改进什么? - Waza_Be
当我颠倒参数时,结果仍然相同。我得到了与之前相同的效果,但是有一些小问题。这就是我的意思。看看当图标被点击时第二个活动是如何弹出的。http://www.youtube.com/watch?feature=endscreen&NR=1&v=eHm9MwjiwQA - Hussein
@jasper,只需在该参数中添加0即可。 - karandeep singh
你在API中找到动画XML文件的位置在哪里? - Michel Feinstein
2个回答

14

尝试在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>

希望这能有所帮助。


4
需要做什么来“从zoom_exit.xml中删除动画”? - Jasper
2
overridePendingTransition(R.anim.zoom_enter_new, 0); 中的参数,将其设置为@Jasper user 0。 - saksham

2

overridePendingTransition(zoom_enter_new, zoom_exit_actual);

第一个参数是指进入的Activity(也就是新的Activity) 第二个参数是指离开的Activity(也就是当前的Activity)

如果你想要达到视频中看起来当前Activity立即消失的效果,那么第二个参数需要设置为0(表示没有动画)

overridePendingTransition(zoom_enter_new, 0);

如果你想让新的Activity像视频一样缩放进入,这是anim xml资源的解释(位于res/anim/目录下的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);

这段代码是用来设置页面跳转时的动画效果,其中R.anim.zoom_enter_new是新页面进入时的动画,0代表旧页面离开时不需要动画效果。

Tobia

这是一个人名,无需翻译。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接