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>

相关推荐

  1. kotlin 退出Activity 平滑动画

    2024-07-18 13:52:01       21 阅读
  2. Android Activity切换动画多种实现方式

    2024-07-18 13:52:01       38 阅读
  3. Android 13屏蔽Activity或包的手势禁止滑动退出

    2024-07-18 13:52:01       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 13:52:01       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 13:52:01       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 13:52:01       57 阅读
  4. Python语言-面向对象

    2024-07-18 13:52:01       68 阅读

热门阅读

  1. C语言面试题

    2024-07-18 13:52:01       21 阅读
  2. 1.1 系统架构概述

    2024-07-18 13:52:01       18 阅读
  3. live555 rtsp服务器实战之doGetNextFrame

    2024-07-18 13:52:01       22 阅读
  4. 依赖倒置原则

    2024-07-18 13:52:01       19 阅读
  5. Python使用队列在两个线程中传递数据

    2024-07-18 13:52:01       18 阅读
  6. STM32判断休眠

    2024-07-18 13:52:01       20 阅读
  7. Spring boot 2.0 升级到 3.3.1 的相关问题 (四)

    2024-07-18 13:52:01       16 阅读
  8. Miniforge 安装器

    2024-07-18 13:52:01       20 阅读