I'm currently transitioning from SwiftUI to Kotlin Compose and struggling with something that should be easy but I maybe tackling in the wrong way.
What I'm trying to do is have an image that is centrally aligned both vertically & horizontally, basically in the centre of the screen. Then I need two text values at the bottom of the screen. How should I tackle this, my current approach is to have a column set to .fillmaxsize() within this I have two rows one with an image, the other with another column with two rows of text and a Spacer(modifier = Modifier.weight(1f)) between the two rows
Everything is correctly horizontally aligned and the two text fields correctly bottom aligned, its the image that I'm unable to vertically centre.
@Composable fun testScreen() { Column(Modifier .background(Color.Blue) .fillMaxSize(), verticalArrangement = Arrangement.Center ) { Row(Modifier .fillMaxWidth() .background(Color.Green), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically ) { Image( painterResource(R.someimagefile), contentDescription = "", contentScale = ContentScale.Crop, modifier = Modifier .size(300.dp) ) } Spacer(modifier = Modifier.weight(1f)) Row(Modifier .background(Color.Red) .fillMaxWidth(), horizontalArrangement = Arrangement.Center, ) { Column() { Text( text = "Text 1", color = Color.Black, textAlign = TextAlign.Center, modifier = Modifier .align(Alignment.CenterHorizontally) ) Text( text = "Text 2", fontSize = 20.sp, color = Color.Black, textAlign = TextAlign.Center, modifier = Modifier .align(Alignment.CenterHorizontally) ) } } } } 