https://kotlinlang.org logo
#compose
Title
# compose
b

brabo-hi

02/04/2022, 4:11 AM
hi all, when using compose i have the following
Copy code
BoxWithConstraints {
   Image(painter = painterResource(id = R.drawable.image), contentDescription = null)
}
how can i make the image
width == parent's width
but the height to keep a constant ration as the original image?
c

Colton Idle

02/04/2022, 4:41 AM
Use the ratio modifier (with like 16/9f) + fillMaxWidth
No need for BWC
a

Albert Chang

02/04/2022, 4:50 AM
To maintain the original aspect ratio, you can simply use
contentScale = ContentScale.FillWidth
.
👍 2
c

Colton Idle

02/04/2022, 5:20 AM
@Albert Chang no boxWithConstraints needed, right?
a

Albert Chang

02/04/2022, 5:20 AM
Yep
👍 3