【问题标题】:How to use Modifier.contentSize in Jetpack Compose?如何在 Jetpack Compose 中使用 Modifier.contentSize?
【发布时间】:2021-04-04 00:35:48
【问题描述】:

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

If you are animating changes to content size:
Use Modifier.contentSize.

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

【问题讨论】:

    标签: 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

    【讨论】:

    • 不错。看起来是文档中的错字。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-15
    • 2022-12-09
    • 2021-07-14
    • 2020-04-23
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    相关资源
    最近更新 更多