无法为约束布局导入createRefs()



我的导入

它要求我导入Focus请求,但我想使用createRef((进行约束布局引用

我使用的是这个版本:;androidx.constraintlayout:constraintllayout compose:1.0.0-rc01";

太晚了,但我遇到了同样的问题并找到了答案。

我忘了用ConstraintLayout包围createRefs。应该是这样的。

ConstraintLayout {
val (button, text) = createRefs()
Button(
onClick = { /* Do something */ },
modifier = Modifier.constrainAs(button) {
top.linkTo(parent.top, margin = 16.dp)
}
) {
Text("Button")
}
Text("Text", Modifier.constrainAs(text) {
top.linkTo(button.bottom, margin = 16.dp)
})
}

你应该导入这个。

import androidx.constraintlayout.compose.ConstraintLayout

我希望这能帮助你

当你想写你的"约束集";注意不要添加";androidx.compose

最新更新