0

I'm using coil library to load images in my composable view and I want to define fix height and width for my coil Image composable, however the modifier is missing in the coil Image composable class, following is the code snippet I'm using.

AsyncImage(
        model = limit.imgUrl,
        contentDescription = null
    )

How I can make the width and height fixed irrespective of the image resolution.

HAXM
  • 3,578
  • 4
  • 31
  • 38
  • 3
    Every `AsyncImage` function in coil library has `Modifier` param. https://github.com/coil-kt/coil/blob/main/coil-compose-base/src/main/java/coil/compose/AsyncImage.kt – Thracian Aug 24 '22 at 12:27

2 Answers2

3

Just apply modifier = Modifier.height(xx.dp).width(xx.dp) to the AsyncImage:

   AsyncImage(
        //...
        modifier = Modifier.height(300.dp).width(100.dp)
    )
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
1

Use the Modifier to set the width and height, but be sure to set contentScale = ContentScale.FillBounds, or it won't resize the image properly:

AsyncImage(
   model = limit.imgUrl,
   contentDescription = null,
   contentScale = ContentScale.FillBounds,
   modifier = Modifier.height(60.dp).width(80.dp)
)
Ammon
  • 121
  • 1
  • 3