如何在合成中设置约束宽度/高度?
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这个等于
android:layout_width="wrap_content"
app:layout_constrainedWidth="true"
?
3条答案
按热度按时间wko9yo5t1#
您可以使用
dkqlctbz2#
使用
Dimension.preferredWrapContent
对我很有效:更多信息- https:Kotlin#首选 Package 内容()
n8ghc7c13#
在constraintLayout中下面是各种宽度和高度模式的示例。
preferredWrapContent
、fillToConstraints
、preferredValue(x.dp)
将分别默认为 wrap、constrained 或 filled。但将至少强制附加约束,等等。