我目前正在使用Jetpack Compose中的自定义布局.这是我到目前为止所得到的测试结果:
@Preview(widthDp = 1000, heightDp = 1000)
@Composable
fun MyLayout() {
Layout({ Box(Modifier.size(48.dp).background(Color.Blue)) }) { measurables, constraints ->
val placeables = measurables.map { it.measure(constraints) }
layout(constraints.maxWidth, constraints.maxHeight) {
placeables.forEach { it.place(0, 0) }
}
}
}
我这里的问题是Box
填充了整个布局,而不仅仅是48.dp
的大小.有人能解释一下为什么会这样吗?我读了here篇关于创建自定义布局的文章,但找不到任何有用的东西.