Android 活动退出转换未完全插值

发布于 2025-01-10 03:02:11 字数 1166 浏览 1 评论 0原文

我已将 Activity 的 exitTransition 设置为类似于

window.exitTransition = object : Visibility() {
  override fun onDisappear(
        sceneRoot: ViewGroup?,
        startValues: TransitionValues?,
        startVisibility: Int,
        endValues: TransitionValues?,
        endVisibility: Int
    ): Animator {
        return ValueAnimator.ofFloat(0f, 1f).apply {
            addUpdateListener { animator ->
                // do something with animator.animatedFraction
            }
            setDuration(1000)
        }
    }
}

使用 onAppear 的 EnterTransition。

设置转换后在 Activity 之间进行转换时:

val intent = Intent(activity, HomeActivity::class.java)
    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
val options = ActivityOptions.makeSceneTransitionAnimation(activity).toBundle()
activity.startActivity(intent, options)

在我的 Android 11 设备上,我的进入动画会获取所有更新,但退出动画在被切断之前仅短暂播放。例如,更新侦听器将被调用为 0.0 -> 。 0.3,然后直接跳到1.0。我在过渡对象中设置的持续时间似乎也根本没有得到尊重。

我在这里遗漏了什么,还是 Android 的活动转换动画插值器损坏了?

I have set my activity's exitTransition to be something like

window.exitTransition = object : Visibility() {
  override fun onDisappear(
        sceneRoot: ViewGroup?,
        startValues: TransitionValues?,
        startVisibility: Int,
        endValues: TransitionValues?,
        endVisibility: Int
    ): Animator {
        return ValueAnimator.ofFloat(0f, 1f).apply {
            addUpdateListener { animator ->
                // do something with animator.animatedFraction
            }
            setDuration(1000)
        }
    }
}

The enterTransition is similar using onAppear.

When transitioning between activities after setting the transitions:

val intent = Intent(activity, HomeActivity::class.java)
    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
val options = ActivityOptions.makeSceneTransitionAnimation(activity).toBundle()
activity.startActivity(intent, options)

On my Android 11 device, my enter animation gets all of its updates, but the exit animation is played only briefly before being cut off. E.g., the update listener will be called for 0.0 -> 0.3 and then skip straight to 1.0. And the duration I set in the transition object doesn't seem to be respected at all either.

Is there something I'm missing here or is Android's activity transition animation interpolator busted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梓梦 2025-01-17 03:02:11

问题是我超越了动画师的持续时间。看来你不能这样做。

The issue was that I was overriding the duration of the animator. It seems you can't do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文