android - 不能在约束中表示 214748364 的大小

标签 android android-jetpack-compose android-jetpack-compose-layout

我刚刚创建了一个简单的 Composable,并希望使用 Layout 来渲染它。 ,但是在实现解决方案时,我在测量阶段偶然发现了这个错误。

java.lang.IllegalArgumentException: Can't represent a size of 214748364 in Constraints
        at androidx.compose.ui.unit.Constraints$Companion.bitsNeedForSize(Constraints.kt:408)
        at androidx.compose.ui.unit.Constraints$Companion.createConstraints-Zbe2FdA$ui_unit_release(Constraints.kt:368)
        at androidx.compose.ui.unit.ConstraintsKt.Constraints(Constraints.kt:438)
        at androidx.compose.ui.unit.ConstraintsKt.Constraints$default(Constraints.kt:423)
        at com.gmarsk.aiare.MainActivity$InstructionsScreen$DisplayCard$1.measure-3p2s80s(MainActivity.kt:514)
        at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:54)
这是我尝试这个的时候
val sampleComposable = measurables[1].measure(
                Constraints(
                    minHeight = constraints.maxHeight * 7 / 10,
                )
            )
以前有人偶然发现过这个吗?如果不是错误,解决方案是什么,在这种情况下,请告诉我。
现在,我认为这里的问题是我嵌套了两个 Layout可组合物,
Layout(
content = {
 Dummy1()
 Dummy2()
 NestedLayoutComposable() // It contains a Layout Composable itself
}{ measurables, constraints ->
 val nlc = measurables[2].measure(
  Constraints(
   minHeight = constraints.maxHeight * 7/10
  )
 )
 layout(constraints.maxWidth, constraints.maxHeight){
  nls.place(0, 0)
 }
}
)
其中 nestedLayoutComposable 再次有一个 Layout 并且这就是发生崩溃的地方,它在这一行
            Layout(
                content = {
                    Text(text = "Random")
                    Box {
                        Image(painter = AppUtils.getRandomImagePainter(), contentDescription = "")
                    }
                }
            ) { measurables, constraints ->
                val text = measurables[0].measure(constraints)
/*This line -->*/   val image = measurables[1].measure(
                    Constraints(
                        maxWidth = constraints.maxWidth * 90 / 100,
                        minHeight = constraints.maxHeight * 7 / 10
                    )
                )

                layout(constraints.maxWidth, constraints.maxHeight) {
                    instruction.place(
                        (constraints.maxWidth - instruction.width) / 2,
                        0
                    )
                    illustration.place(
                        (constraints.maxWidth - illustration.width) / 2,
                        illustration.height / 2
                    )
                }
            }

所以我知道问题出在 Layout Composable 相互嵌套,但这仍然不能解释为什么会发生错误,以及如何解决它,所以这些是这篇文章的主要问题,这就是我希望答案包含的内容,谢谢。

最佳答案

在我的情况下,类似的崩溃是由另一个可滚动列内的可滚动列引起的。检查您的撰写层次结构中是否没有这种情况。

关于android - 不能在约束中表示 214748364 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71400647/

相关文章:

android - 将框/列与屏幕底部对齐 Jetpack Compose

android - 在牛轧糖上打开 PDF

android - 我怎样才能阻止我的 fragment 被破坏?

kotlin - 带注释的可为空类型的条件值声明抛出 'type inference failed'

android - 不要在 Compose 中裁剪 AndroidView 的边界

android - 在 jetpack compose 中对齐行项目

java.net.ConnectException : failed to connect to localhost/127. 0.0.1(端口 9090):连接失败:ECONNREFUSED(连接被拒绝)

Android:如何安排?

android - Jetpack 根据动态宽度撰写下一行的行项目