如何在Jetpack Compose的列内居中放置元素>>

问题描述 投票:0回答:1

如何将元素居中嵌入在行内的第一列中:

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))
                    }
                 }
             }
         }
     }
}

在此示例中,我对填充进行了硬编码,但无法弄清楚如何将元素居中放置在框外。如果没有这样的选择,如何获得整个行的高度?

<<

Container(alignment = Alignment.TopCenter)或Center {}将为您提供帮助。

android android-layout kotlin android-jetpack android-jetpack-compose
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.