How do I set the layout_constraintHorizontal_bias prop on a Composable that is in a Constraint Layout? Here is the XML code:
<TextView
...
tool:layout_constraintStart_toStartOf="parent"
tool:layout_constraintEnd_toEndOf="parent"
tool:layout_constraintWidth_max="wrap"
tool:layout_constraintHorizontal_bias="0"/>
Here is how my Jetpack Compose code looks right now:
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")
}
}
So my question is how do I set the horizontal bias of Button 2 to be 0?
You have to use the
linkTo
function of theConstrainScope
which has more parameters: