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

Liangjun Sha
- 105
- 1
- 6
-
1is this an answer for you ?https://stackoverflow.com/questions/59713224/jetpack-compose-column-gravity-center – PedroAGSantos Sep 13 '21 at 06:42
-
Where is the problem to use a `Box` or a `Column` as container? – Gabriele Mariotti Sep 13 '21 at 12:19
-
@GabrieleMariotti no problems actually, I just wanna to find out whether a container is needed – Liangjun Sha Sep 14 '21 at 05:52
2 Answers
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