【问题标题】:Android vertical transition animation like IOS between activity/fragmentActivity/Fragment之间类似IOS的Android垂直过渡动画
【发布时间】:2021-06-24 13:54:55
【问题描述】:

我正在尝试在 Activity/Fragments 之间实现过渡动画,就像默认的 iOS 动画一样。是否有任何库或默认方式来实现此行为?

【问题讨论】:

    标签: android android-fragments android-animation android-transitions


    【解决方案1】:

    是的,这是可能的。

    在启动新意图后使用overridePendingTransition。它看起来像这样。

    val intent = Intent(this, SecondActivity::class.java)
    startActivity(intent)
    overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out)
    

    push_up_in.xml 和 push_up_out.xml 必须在 app/src/main/res/anim/ 中定义

    push_up_in

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
     <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="5000"/>
     <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="5000" />
    </set>
    

    push_up_out

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
     <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="5000"/>
     <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="5000" />
    </set>
    

    当我想更改过渡动画时,我使用了以下资源: https://www.mysamplecode.com/2013/02/android-animation-switching-activity.html

    动画 xml 文件取自那里。动画可以随意更改。例如,持续时间很长。要实现与 iOS 上完全相同的行为,您需要进行调整。

    【讨论】:

    • 这不是必需的行为请再看动画
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 2017-02-10
    • 1970-01-01
    • 2016-10-20
    • 2014-11-02
    • 1970-01-01
    相关资源
    最近更新 更多