Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set modifier height width to coil Image or AsyncImage and scal the image loaded from url

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.

like image 880
HAXM Avatar asked Oct 12 '25 11:10

HAXM


1 Answers

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)
)
like image 79
Ammon Avatar answered Oct 14 '25 23:10

Ammon