如何Row按基线对齐 a 内的元素。我的问题是我想要一个Row包含多个Text元素的元素,并且每个Text元素都有不同的字体和大小。默认情况下,它们在顶部对齐。我需要它们在底部对齐。这是代码:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Row {
Text(
text = "Abrakadabra",
style = TextStyle(fontSize = 22.sp, fontWeight = FontWeight.Bold)
)
Text(
text = "Abrakadabra",
style = TextStyle(fontSize = 14.sp, fontWeight = FontWeight.Bold)
)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是代码的渲染视图:
android android-layout kotlin android-jetpack android-jetpack-compose
如何将嵌入行内的第一个列中的元素居中:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Row {
Column(modifier = LayoutPadding(top = 16.dp)) {
Text(text = "Centered ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
}
Column {
Text(text = "Line One ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
Text(text = "Line Two ", style = TextStyle(fontSize = 30.sp, fontWeight = FontWeight.Bold))
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,我对填充进行了硬编码,但无法弄清楚如何将元素置于框外居中。如果没有这样的选项,我怎样才能得到整行的高度?
android android-layout kotlin android-jetpack android-jetpack-compose