gpt4 book ai didi

android - 如何在 Constraint Layout Compose 中使用偏差

转载 作者:行者123 更新时间:2023-12-04 11:51:48 26 4
gpt4 key购买 nike

如何在约束布局中的 Composable 上设置 layout_constraintHorizo​​ntal_bias Prop ?这是 XML 代码:

<TextView
...
tool:layout_constraintStart_toStartOf="parent"
tool:layout_constraintEnd_toEndOf="parent"
tool:layout_constraintWidth_max="wrap"
tool:layout_constraintHorizontal_bias="0"/>
这是我的 Jetpack Compose 代码现在的样子:
ConstraintLayout(modifier = modifier.fillMaxSize()) {
val (button1, button2) = createRefs()
Button(
onClick = {},
modifier = Modifier.constrainAs(button1) {
top.linkTo(parent.top, margin = 16.dp)
}
) {
Text(text = "Button 1")
}

Button(
onClick = {},
modifier = Modifier.constrainAs(button2) {
top.linkTo(button1.bottom, margin = 4.dp)
start.linkTo(button1.end, margin = 20.dp)
end.linkTo(parent.end, margin = 20.dp)
width = Dimension.preferredWrapContent
}
) {
Text(text = "Button 2")
}
}
所以我的问题是如何将 Button 2 的水平偏差设置为 0?

最佳答案

您必须使用 linkTo ConstrainScope 的功能其中有更多参数:

ConstraintLayout(modifier = modifier.fillMaxSize()) {
val (button1, button2) = createRefs()
Button(
onClick = {},
modifier = Modifier.constrainAs(button1) {
top.linkTo(parent.top, margin = 16.dp)
}
) {
Text(text = "Button 1")
}

Button(
onClick = {},
modifier = Modifier.constrainAs(button2) {
top.linkTo(button1.bottom, margin = 4.dp)
linkTo(button1.end, parent.end, startMargin = 20.dp, endMargin = 20.dp, bias = 0F)
width = Dimension.preferredWrapContent
}
) {
Text(text = "Button 2")
}
}

关于android - 如何在 Constraint Layout Compose 中使用偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64171607/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com