windowSplashScreenAnimationDuration是用来做什么的?

3
Android中的启动画面API引入了windowSplashScreenAnimationDuration。有人注意到它对启动画面持续时间或动画持续时间有任何影响吗?即使我将其设置为建议的最大值1000ms,有时启动画面的可见时间也少于此时间。如果我将其设置为100ms,则启动画面可见时间更长。
此外,无论我的实际可绘制(xml)动画持续多长时间,windowSplashScreenAnimationDuration似乎都没有影响。
文档也相当差劲。
能否有人解释一下这个问题?
谢谢!
2个回答

1

windowSplashScreenAnimationDuration 对显示时间没有直接影响。您可以使用 SplashScreenView#getIconAnimationDuration 来检索持续时间值,并在自己的业务逻辑中使用该值。

来自 https://developer.android.com/guide/topics/ui/splash-screen#suspend-drawing

使用 windowSplashScreenAnimationDuration 指示闪屏图标动画的持续时间。设置此项不会对实际显示闪屏时间产生任何影响,但是您可以在使用 SplashScreenView#getIconAnimationDuration 自定义闪屏退出动画时检索它。有关详细信息,请参见以下部分中的“保持闪屏更长时间”。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // ...

    // Add a callback that's called when the splash screen is animating to
    // the app content.
    splashScreen.setOnExitAnimationListener { splashScreenView ->
        // Create your custom animation.
        val slideUp = ObjectAnimator.ofFloat(
            splashScreenView,
            View.TRANSLATION_Y,
            0f,
            -splashScreenView.height.toFloat()
        )
        slideUp.interpolator = AnticipateInterpolator()
        slideUp.duration = 200L

        // Call SplashScreenView.remove at the end of your custom animation.
        slideUp.doOnEnd { splashScreenView.remove() }

        // Run your animation.
        slideUp.start()
    }
}


// Get the duration of the animated vector drawable.
val animationDuration = splashScreenView.iconAnimationDuration
// Get the start time of the animation.
val animationStart = splashScreenView.iconAnimationStart
// Calculate the remaining duration of the animation.
val remainingDuration = if (animationDuration != null && animationStart != null) {
    (animationDuration - Duration.between(animationStart, Instant.now()))
        .toMillis()
        .coerceAtLeast(0L)
} else {
    0L
}

0

目前,androidx.core:core-splashscreen 的版本为 1.0.0-alpha01。

看起来 windowSplashScreenAnimationDuration 值仅用于 v31 android:windowSplashScreenAnimationDuration。

https://android.googlesource.com/platform/frameworks/support/+/049995bd740483b4742affb9095889fb8bb9a735/core/core-splashscreen/src/main/res/values-v31/styles.xml#23

    <item name="android:windowSplashScreenAnimationDuration">
       ?windowSplashScreenAnimationDuration
   </item>

因此,在 Android 12 平台之前,windowSplashScreenAnimationDuration 没有任何效果。该值仅在 Android 12(及以上版本)中生效。


我正在 Android 12 上进行测试。 - Michael Bolboceanu
你应该为Android 12平台添加“android:”前缀。尝试使用“android:windowSplashScreenAnimationDuration”。 “windowSplashScreenAnimationDuration”可与androidx.core:core-splashscreen库和Theme.SplashScreen主题一起使用。 - irgaly
"windowSplashScreenAnimationDuration" 在 API 32 上无法正常工作。 - Vidyesh Churi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接