0

I’d like to find some properties like android:gravity=“center_vertical” in Jetpack Compose without using Column, any ideas?

Liangjun Sha
  • 105
  • 1
  • 6

2 Answers2

1

No, the only way is to use a container. And that is exactly how it should be used in Compose: the container does not add any problems, unnecessary load, etc. No reason why you should avoid them.

To me, using Column is not the most logical solution, because it is designed to vertically arrange several elements.

For a single item, Box is more clear to me:

Box(
    contentAlignment = Alignment.Center,
    modifier = Modifier.fillMaxSize()
) {
    Text("Hello")
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
1

You can't place a text vertically center without using a container. But you can change the alignment of Text without using a container.

Text(textAlign: TextAlign.Center)

In case of height with wrapContent this will automatically place the text vertically centered.

Other values of TextAlign are Left, Right, Justify, Start and End

S Haque
  • 6,881
  • 5
  • 29
  • 35