如何在Jetpack Compose中使用Modifier.contentSize?

5
1个回答

12
我认为你正在谈论的是animateContentSize函数。
这里有一个可能会有所帮助的示例。
Column(
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp)
            // This `Column` animates its size when its content changes.
            .animateContentSize()
    ) {
        Row {
            Icon(
                imageVector = Icons.Default.Info,
                contentDescription = null
            )
            // ...
        }
        if (expanded) { // If the expanded value is changed then the animateContentSize will be triggered
            Spacer(modifier = Modifier.height(8.dp))
            Text(
                text = stringResource(R.string.lorem_ipsum),
                textAlign = TextAlign.Justify
            )
        }
    }

这里输入图片描述

来自Jetpack Compose 动画 codelab


不错。看起来文档中有一个打字错误。 - Elye

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