【问题标题】:Zoom out Transition animation between two activities缩小两个活动之间的过渡动​​画
【发布时间】:2017-05-16 17:07:26
【问题描述】:

我检查了 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);

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

【问题讨论】:

  • 您是否尝试过反转 R.anim.zoom_enter 并退出?出了什么问题,你想改进什么?
  • 当我反转参数时它仍然是一样的。我得到了和以前一样的效果,但有一些小故障。这就是我的意思。查看单击图标时第二个活动如何弹出。youtube.com/watch?feature=endscreen&NR=1&v=eHm9MwjiwQA
  • @jasper,只需在该参数中添加 0。
  • 您在 API 中哪里找到动画 XML?

标签: android android-animation


【解决方案1】:

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

希望这会有所帮助。

【讨论】:

  • 需要做什么:“从zoom_exit.xml中移除动画”?
  • @Jasper user 0 为那个参数 overridePendingTransition(R.anim.zoom_enter_new, 0);
【解决方案2】:

overridePendingTransition(zoom_enter_new, zoom_exit_actual);

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

因此,如果您想制作与视频相同的效果, 实际活动立即隐藏,第二个参数需要设置为 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);

托比亚

【讨论】:

    猜你喜欢
    • 2012-03-24
    • 2012-08-19
    • 2011-03-31
    • 2012-06-08
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2020-09-27
    相关资源
    最近更新 更多