如何在 Jetpack Compose 中使用 Modifier.contentSize?
How to use Modifier.contentSize in Jetpack Compose?
在https://developer.android.com/jetpack/compose/animation
If you are animating changes to content size:
Use Modifier.contentSize.
但是,我找不到如何访问 Modifier.contentSize
和使用它。有指导吗?
我认为您在谈论 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 Animation codelab:
在https://developer.android.com/jetpack/compose/animation
If you are animating changes to content size:
Use Modifier.contentSize.
但是,我找不到如何访问 Modifier.contentSize
和使用它。有指导吗?
我认为您在谈论 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 Animation codelab: