Как центрировать элементы внутри колонки в Jetpack Compose - PullRequest
0 голосов
/ 01 марта 2020

Как центрировать элементы внутри первого столбца, который встроен в строку:

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

В этом примере я жестко закодировал заполнение, но не смог понять, как центрировать элементы из коробки. , Если такой опции нет, как я могу получить высоту всей строки?

1 Ответ

0 голосов
/ 03 марта 2020

Контейнер (выравнивание = Alignment.TopCenter) или Центр {} помогут вам.

Попробуйте,

    MaterialTheme {
        Row {
            Container(width = 200.dp) {
                Center {
                    Column() {
                        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))
            }
        }
    }

или

    MaterialTheme {
        Row {
            Container(width = 200.dp, alignment = Alignment.TopCenter) {
                    Column() {
                        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))
            }
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...