I've been currently developing and learning android jetpack compose and there are some things I don't know and wonder about this. One thing I'm wondering I'm trying to do a back button positioned in the upper left corner of the screen and a text positioned in the middle. I originally wrote this code like this:
Row(modifier = Modifier
.padding(5.dp)
.fillMaxWidth()) {
Image(
modifier = Modifier
.clickable {
onBackClick()
}
.padding(4.dp),
alignment = Alignment.CenterStart,
painter = painterResource(id = R.drawable.ic_back),
contentDescription = "back")
Row(
horizontalArrangement = Arrangement.Center){
Text(text = "Help")
}
}
Since I gave a modifier.FillMaxWidth in the first Row, I didn't give it in the second because it has a child component, I thought it was unnecessary, and I gave a horizontalArrangment center in the second Row to align the Text in the middle, but even though I did this, the back button and the text appeared side by side on the upper left.
However, when I rewrote my code like this, when I added the second Row modifier.FillMaxWidth, it worked fine.
Row(modifier = Modifier
.padding(5.dp)
.fillMaxWidth()) {
Image(
modifier = Modifier
.clickable {
onBackClick()
}
.padding(4.dp),
alignment = Alignment.CenterStart,
painter = painterResource(id = R.drawable.ic_back),
contentDescription = "back")
Row(modifier = Modifier.fillMaxWidth(), // <----
horizontalArrangement = Arrangement.Center){
Text(text = "Yardım")
}
}
I added this modifier = Modifier.fillMaxWidth() second Row component
Why is it necessary to give Modifier.fillMaxWidth() on the second Row? We already give it in the parent component? what's going on in the background?