小编Tig*_*yan的帖子

如何在 Jetpack Compose 中按基线对齐行元素

如何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

12
推荐指数
1
解决办法
4954
查看次数

如何在 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

4
推荐指数
1
解决办法
9246
查看次数