如何在JetpackCompose中使用Modifier.contentSize?

在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动画代码实验室:


以上是如何在JetpackCompose中使用Modifier.contentSize?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>