Here I'm using Modifier.fillMaxWidth
and the items doesn't make parent column larger :
@Composable
fun Demo() {
Column(modifier = Modifier.width(300
.dp)) {
Text(text = "with fillMaxWidth modifier",modifier = Modifier.fillMaxWidth().background(Color.Red))
Text(text = "without fillMaxWidth modifier",modifier = Modifier.background(Color.Gray))
}
}
What I usually do to achieve the matchParentWidth
is something like this (It's dirty but gets the job done):
val context = AmbientContext.current.resources
val displayMetrics = context.displayMetrics
val scrWidth = displayMetrics.widthPixels / displayMetrics.density
Column(modifier = Modifier.width(300
.dp)) {
Text(text = "with fillMaxWidth modifier",modifier = Modifier.fillMaxWidth().background(Color.Red))
Text(text = "without fillMaxWidth modifier",modifier = Modifier
.preferredWidth(scrWidth.dp)
.background(Color.Gray))
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…