【问题标题】:Compose - AnimatedVisibility and offsetCompose - AnimatedVisibility 和偏移量
【发布时间】:2022-10-06 22:42:17
【问题描述】:

在向AnimatedVisibility 添加进入和退出过渡时,如果可组合动画具有偏移修改器,则过渡不可见:

AnimatedVisibility(
            visible = visible,
            enter = fadeIn(animationSpec = tween(1000)),
            exit = fadeOut(animationSpec = tween(1000))
        ) {
            Text(
                text = "Hello, world!", modifier = Modifier
                    // This will make the transition not working
                    //.offset(100.dp, 0.dp)
            )
        }
        Button(onClick = { visible = !visible }) {
            Text("Click Me")
        }

这是没有偏移的动画:

这是带有偏移量的动画:

有没有办法让它工作?

【问题讨论】:

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


    【解决方案1】:

    不要将偏移修改器放到Text 上。把它放到AnimatedVisibility 上:

    AnimatedVisibility(
                visible = visible,
                enter = fadeIn(animationSpec = tween(1000)),
                exit = fadeOut(animationSpec = tween(1000)),
                modifier = Modifier.offset(100.dp, 0.dp)
            ) {
                Text(text = "Hello, world!")
            }
    

    【讨论】:

    • 谢谢,我没有考虑。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多