Why the width of red circle equal to with of gray area?
Here are my code and result, Hope someone answers.
@Preview
@Composable
fun testContent() {
Scaffold { paddingValues ->
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
modifier = Modifier
.fillMaxWidth(1f)
.aspectRatio(0.8f)
.clip(RoundedCornerShape(size = 6.dp))
.background(Color.Gray)
.fillMaxWidth(0.8f)
.aspectRatio(ratio = 1f)
.clip(CircleShape)
.background(Color.Red),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "I am text",
color = Color.White,
)
Text(
text = "I am text too",
color = Color.White,
)
}
}
}
}
result is here: https://i.stack.imgur.com/qUUNM.png
Because in Column Composable (which draws/clips red circle) you have a parameter Modifier.fillMaxWidth(1f), thus it takes the maximum width of the parent
1f is is a fraction parameter and if you make it less it will take less width
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.