How to set constrained width/height in Compose?
Text("Test", Modifier.constrainAs(text) {
linkTo(
start = parent.start,
top = button.bottom,
end = parent.end,
bottom = parent.bottom,
topMargin = 16.dp,
horizontalBias = 0f
)
width = Dimension.wrapContent // this is default, can be removed
// now I need to set constrainedWidth somehow like in XML app:layout_constrainedWidth
})
width = Dimension.preferredWrapContent mb this one is equal to
android:layout_width="wrap_content"
app:layout_constrainedWidth="true"
?
using Dimension.preferredWrapContent worked for me:
modifier = Modifier.constrainAs(content) {
width = Dimension.preferredWrapContent
linkTo(
start = parent.start,
top = button.bottom,
end = parent.end,
bottom = parent.bottom,
topMargin = 16.dp,
horizontalBias = 0f
)
}
for more info - https://developer.android.com/reference/kotlin/androidx/constraintlayout/compose/Dimension.Companion#preferredWrapContent()
You can use
width = Dimension.fillToConstraints
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With