Is there a function in Jetpack Compose similar to the 'ZStack' grouping in SwiftUI

Viewed 544

I was building a calendar app in SwiftUI and decided to move it to the Jetpack Compose to have a version for Android as well. For the SwiftUI version, I was using a ZStack group to overlay the event cards on the time headings. Is there any way to overlay two divs in Kotlin like in SwiftUI?

1 Answers

Well, you can use a Box and set the z-Index using zIndex modifier.

Box {
    Box(
        Modifier
            .size(100.dp)
            .background(Color.Red)
            .zIndex(1f)
    )
    Box(
        Modifier
            .size(100.dp)
            .background(Color.Green)
            .zIndex(2f)
    )
    Box(
        Modifier
            .size(100.dp)
            .background(Color.Blue)
            .zIndex(3f)
    )
}

The highest zIndex will be in front of the others. If you don't define a zIndex, the last one will be closest one.

Related