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

Ely*_*lye 1 android android-jetpack-compose

https://developer.android.com/jetpack/compose/animation

If you are animating changes to content size:
Use Modifier.contentSize.
Run Code Online (Sandbox Code Playgroud)

但是,我找不到如何访问Modifier.contentSize和使用它。任何指南?

Wil*_*ran 6

我认为您在谈论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
            )
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

来自 Jetpack Compose动画代码实验室