android - 如何在撰写中控制 AnimatedVisibility 的持续时间?

标签 android kotlin android-jetpack android-jetpack-compose

我在我的项目中使用了 compose AnimatedVisibility,
但是动画是我需要的缩写。
有相关的API吗?

最佳答案

这是取自 codelabs 的示例.您可以使用每个动画的 durationMillis 添加自己的动画规范,一个用于进入,一个用于退出:

 AnimatedVisibility(
    visible = shown,
    enter = slideInVertically(
        // Enters by sliding down from offset -fullHeight to 0.
        initialOffsetY = { fullHeight -> -fullHeight },
        animationSpec = tween(durationMillis = 150, easing = LinearOutSlowInEasing)
    ),
    exit = slideOutVertically(
        // Exits by sliding up from offset 0 to -fullHeight.
        targetOffsetY = { fullHeight -> -fullHeight },
        animationSpec = tween(durationMillis = 250, easing = FastOutLinearInEasing)
    )
) {
    Surface(
        modifier = Modifier.fillMaxWidth(),
        color = MaterialTheme.colors.secondary,
        elevation = 4.dp
    ) {
        Text(
            text = stringResource(R.string.edit_message),
            modifier = Modifier.padding(16.dp)
        )
    }
}

关于android - 如何在撰写中控制 AnimatedVisibility 的持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68752661/

相关文章:

android - 如何确保当前Fragment在ViewPager中可见

android - Android运行时去哪里找资源文件?

android - Kotlin - 覆盖方法中的 IllegalArgumentException

android - Room 返回的 Livedata GC 后不会触发

android - 如何使用 Jetpack Compose 处理 Activity.onActivityResult()?

android - PhoneGap Android从3.7.0到4.0.2跨域XHR 404的

android - Context.startForegroundService() 然后没有调用 Service.startForeground() - 仍然是一个问题

android - java.lang.RuntimeException : Failed to call observer method when starting Fragment with EditText (number) Two way databinding 错误

android - 从 View 中插入带有房间的数据 : Cannot access database on the main thread

Kotlin when(Pair<>),还有其他方法吗?