Android Jetpack Compose 尺寸随持续时间变化的动画

Dmi*_*tri 5 animation android android-animation kotlin android-jetpack-compose

如何在 Jetpack Compose 中添加内容大小更改动画的持续时间?尝试使用Modifier.animateContentSize()并传递带有持续时间的animationSpec,但它只是突然插入或弹出,没有观察到持续时间。

Column() {
     Modifier.animateContentSize
       (animationSpec = tween(durationMillis = 5000,
       easing = LinearEasing))
     if (!isTabInvisible) {
             //some content goes here
                                
      }
 }
             
Run Code Online (Sandbox Code Playgroud)

小智 3

我建议您使用 animateDpAsState,而不是 animateContentSize:

val animatedSize by animateDpAsState(
    targetValue = /*condition Here*/, animationSpec = tween(
        durationMillis = 5000,
        easing = LinearEasing
    )
)
Run Code Online (Sandbox Code Playgroud)