windowSplashScreenAnimationDuration
。有人注意到它对启动画面持续时间或动画持续时间有任何影响吗?即使我将其设置为建议的最大值1000ms,有时启动画面的可见时间也少于此时间。如果我将其设置为100ms,则启动画面可见时间更长。此外,无论我的实际可绘制(xml)动画持续多长时间,
windowSplashScreenAnimationDuration
似乎都没有影响。文档也相当差劲。
能否有人解释一下这个问题?
谢谢!
windowSplashScreenAnimationDuration
。有人注意到它对启动画面持续时间或动画持续时间有任何影响吗?即使我将其设置为建议的最大值1000ms,有时启动画面的可见时间也少于此时间。如果我将其设置为100ms,则启动画面可见时间更长。windowSplashScreenAnimationDuration
似乎都没有影响。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
}
目前,androidx.core:core-splashscreen 的版本为 1.0.0-alpha01。
看起来 windowSplashScreenAnimationDuration 值仅用于 v31 android:windowSplashScreenAnimationDuration。
<item name="android:windowSplashScreenAnimationDuration">
?windowSplashScreenAnimationDuration
</item>
因此,在 Android 12 平台之前,windowSplashScreenAnimationDuration 没有任何效果。该值仅在 Android 12(及以上版本)中生效。