# compose


03/04/2021, 1:50 AM
Is there a way to change the order of drawing for deep descendants (not direct children) of the same parent? I'm trying
, but it only works "for the children of the same layout parent". Code in the thread.
🚫 1
Copy code
fun ZIndexPreview() {
    val z1 = Modifier.zIndex(1f)
    val z2 = Modifier.zIndex(2f)
    val z3 = Modifier.zIndex(3f)

    Box(contentAlignment = Alignment.Center) {
        SomeBox("Magenta", Color.Magenta, textModifier = z3, modifier = z1)
        JustText("Blue", Color.Blue, modifier = z2.offset(x = 20.dp, y = 40.dp))

fun JustText(text: String, color: Color, modifier: Modifier) {
        fontSize = 40.sp,
        modifier = modifier
            .background(color, shape = RoundedCornerShape(50))
        color = Color.White

fun SomeBox(text: String, color: Color, textModifier: Modifier, modifier: Modifier) {
    Box(modifier.background(Color.Cyan).requiredSize(200.dp), contentAlignment = Alignment.Center) {
        JustText(text, color, modifier = textModifier)
I want the Magenta to be drawn over the Blue. And Blue should be visible avobe the Cyan box.