当前位置:   article > 正文

kotlin 退出Activity 平滑动画

kotlin 退出Activity 平滑动画

1. 先看方法

fun finishActivity() {
    finish()
    if (Build.VERSION.SDK_INT >= 34) {//34及以上的实现方式
        overrideActivityTransition(
            Activity.OVERRIDE_TRANSITION_OPEN,
            R.anim.xxx_from_left,
            R.anim.xxx_to_right
        )
    } else {//34以下的实现方式
        overridePendingTransition(R.anim.xxx_from_left, R.anim.xxx_to_right)
    }
}

2. 在资源的动画文件夹即anim下创建两个文件,即 xxx_from_left  和  xxx_to_right

xxx_from_left:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="-100%p"
        android:toXDelta="0"
        android:duration="240" />
</set>

xxx_to_right:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:duration="240" />
</set>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/854227
推荐阅读
相关标签
  

闽ICP备14008679号