Denis
03/04/2021, 1:50 AM.zIndex
, but it only works "for the children of the same layout parent". Code in the thread.@Preview
@Composable
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))
}
}
@Composable
fun JustText(text: String, color: Color, modifier: Modifier) {
Text(
text,
fontSize = 40.sp,
modifier = modifier
.background(color, shape = RoundedCornerShape(50))
.padding(5.dp),
color = Color.White
)
}
@Composable
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)
}
}