https://kotlinlang.org logo
#compose
Title
# compose
h

Hackdiod

01/31/2020, 11:38 AM
Hello! Do you now, how use Center item for few elements. I have Row>Column*2>Text*4, but Row>Column*2>Center>Column>Text*4 it works incorrectly. I think use Center to each text is the wrong approach.
m

Mihai Popa

01/31/2020, 6:20 PM
Note that Center will fill the available space, and will center its child inside. So if you use it for a child of a Column, it will fill the available space before further siblings can occupy space. What behavior are you trying to achieve? Take a look at LayoutGravity modifiers, they provide alignment without the fill available space behavior
(also note that Center will be deprecated/removed, you should rather use the LayoutAlign.Center modifier)
h

Hackdiod

02/01/2020, 9:41 AM
Thank you for your replay! If I use
Copy code
Text("Test", modifier = Gravity.Center)
it's Ok, but I think if I will use this construction:
Copy code
Text("Test1", modifier = Gravity.Center)
Text("Test2", modifier = Gravity.Center)
Text("Test3", modifier = Gravity.Center)
Text("Test4", modifier = Gravity.Center)
it's not optimal for code. But If I use:
Copy code
Column(modifier = Gravity.Center) {
Text("Test1")
Text("Test2")
Text("Test3")
Text("Test4")
}
it's not working for me.
4 Views