spierce7
05/06/2022, 4:44 PMImage
, without knowing it’s size, how could I center something on top of the image? I want the the Image
size to dictate the size of the parent Box
. How could I do this in compose?Oleksandr Balan
05/06/2022, 4:57 PM.align(Alignment.Center)
to center something in the box.
Box {
Image(
painter = painterResource(R.drawable.jigglypuff),
contentDescription = null,
modifier = Modifier
.border(2.dp, Color.LightGray)
)
Text(
text = "Jigglypuff",
modifier = Modifier
.background(Color.LightGray)
.align(Alignment.Center)
)
}
Or alternatively you may set contentAlignment
on the Box component.
Box(
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(R.drawable.jigglypuff),
contentDescription = null,
modifier = Modifier
.border(2.dp, Color.LightGray)
)
Text(
text = "Jigglypuff",
modifier = Modifier
.background(Color.LightGray)
)
}
Does it work for you?spierce7
05/06/2022, 8:49 PMspierce7
05/06/2022, 8:50 PMOleksandr Balan
05/06/2022, 9:32 PM