【问题标题】:How to use Modifier.contentSize in Jetpack Compose?如何在 Jetpack Compose 中使用 Modifier.contentSize?
【发布时间】:2021-04-04 00:35:48
【问题描述】:
【问题讨论】:
标签:
android
android-jetpack-compose
【解决方案1】:
我认为您在谈论 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 撰写 Animation codelab: