https://kotlinlang.org logo
m

Miguel A. Ruiz

02/21/2020, 10:38 PM
Hi, I have a question, I hope I can explain it properly. I want to show an image with the height fixed (I use a container with a height in dp for that) but I would like to have a width dependent of the image size, I mean to respect the image ratio. How can I achieve that?
z

Zach Klippenstein (he/him) [MOD]

02/21/2020, 10:50 PM
There used to be an
AspectRatio
composable, but I think it recently got turned into a modifier
☝️ 2
m

Miguel A. Ruiz

02/21/2020, 11:39 PM
thanks, that works!
just in case somebody need it. With the version dev05. As you see now this is
LayoutAspectRatio
Copy code
val image = imageResource(R.drawable.war_and_peace)
    val ratio = image.width.toFloat() / image.height.toFloat()
    Container(
        modifier = LayoutHeight.Constrain(0.dp, 120.dp)
                + LayoutAspectRatio(aspectRatio = ratio)
    ) {
        DrawImage(image)
    }
👍 6
3 Views