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

Vinay Gaba

03/07/2020, 6:45 AM
Seeing some weirdness when using
ImagePainter
to display an image. Code in thread..
Here is how I'm using it
Copy code
VerticalScroller {
    Column(LayoutPadding(16.dp)) {
        Text("Load image from the resource folder")
        LocalImageComponent(R.drawable.image)              
     }
}
Copy code
@Composable
fun LocalImageComponent(@DrawableRes resId: Int) {
    val image = loadImageResource(resId)
    image.resource.resource?.let {
        Box(
            modifier = LayoutHeight.Max(200.dp) + ImagePainter(it).toModifier(
    scaleFit = ScaleFit.FillWidth
))
    }
}
This scales the image to occupy the entire width but the text above ends up not being visible. I am wondering if there's something wrong about how I'm setting the constraints.
The Text composable isn't visible and is hidden behind the image. This wasn't happening when I was using
DrawImage
also when I try to make an image with rounded corners, it's not working. Here's the code
Copy code
Clip(shape = RoundedCornerShape(8.dp)) {
    Box(modifier = LayoutHeight.Max(200.dp) + ImagePainter(image).toModifier())
}
k

Kazemihabib1996

03/07/2020, 8:27 AM
I had the same problem, because of the Clip implementation, check this thread: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1583344686271600