我正在研究每个修改者的整个记录. 现在我在理解作文修饰语时遇到了一些问题. 它是.alignBy修饰符. 与方框和文本的对齐方式清晰.文本按其基线对齐. 我可以看到文本的基线在哪里. 洋红色框的中间位置与红色文本的基线位置相同. 如果框更靠近行的顶部,则文本向下滑动.
@Preview(heightDp = 200, backgroundColor = 0xFFCCCCCC, showBackground = true)
@Composable
fun test1() {
Row(Modifier.fillMaxHeight()) {
Box(
modifier = Modifier.size(80.dp, 40.dp)
.alignBy { it.measuredHeight / 2 }
.background(Color.Magenta)
)
Text(
text = "Text 1",
fontSize = 40.sp,
modifier = Modifier.alignByBaseline().background(color = Color.Red)
)
Text(
text = "Text 2",
modifier = Modifier.alignByBaseline().background(color = Color.Cyan)
)
}
}
现在我试着把两个盒子排成一排,现在我不明白怎么对齐了.长方体的基线似乎在它的中间.我需要两次"alignby{}"吗?我找不到好的解释,也找不到能解释我问题的教程.在我看来,Android开发人员的文档和示例没有多大帮助.
@Preview(heightDp = 200, backgroundColor = 0xFFCCCCCC, showBackground = true)
@Composable
fun test2() {
Row(Modifier.fillMaxHeight()) {
Box(
modifier = Modifier.size(80.dp, 40.dp)
.alignBy { it.measuredHeight / 1 }
.background(Color.Magenta)
)
Box(
modifier = Modifier.size(80.dp, 20.dp)
.alignBy { it.measuredHeight / 2 }
.background(Color.Green)
)
}
}
谢谢!