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

Thierry

02/11/2020, 2:01 AM
image.png
ha, got it 🙂
Copy code
@Composable
fun DateSeparator(date: Date) {
    Stack() {
        Align(Alignment.Center) {
            Divider(color = Color.Gray, height = 2.dp)
        }
        Align(Alignment.Center) {
            Surface(color=Color.White) {
                Text("Yesterday", modifier = LayoutPadding(10.dp))
            }
        }
    }
}
z

Zach Klippenstein (he/him) [MOD]

02/11/2020, 2:19 AM
Which version of Compose are you using? That code works for me:
Also
Center
is an abbreviation for
Align(Center)
m

mon

02/11/2020, 3:00 AM
I think you should be using modifiers instead of positioning containers like that. Less nesting that way.
LayoutGravity.Center
works. I also think stack/row/column are missing a
gravity
param. It makes sense to me to set all children's alignment then let each child set their own if they want.
☝️ 1
a

Adam Powell

02/11/2020, 3:58 AM
Yeah the default child gravity param is coming back
🎉 6
t

Thierry

02/11/2020, 5:47 PM
Nice, so far i think alignment is the most confusing aspect of Compose.
Super cool to see the work you guys are doing on Compose. I think it's going to have a massive impact on Android development
❤️ 1
@mon can you clarify what you mean?
👍 1
m

mon

02/12/2020, 4:19 AM
You could do something like
Copy code
Stack {
  Divider(modifier = LayoutGravity.Center, ...)
  Surface(modifier = LayoutGravity.Center, ...) {
    Text(...)
  }
}
I find this way cleaner that having to nest each child in a
Center
or
Align
5 Views