Chris Fillmore
04/20/2021, 8:52 PM@Composable
fun WeightedBox() {
Row {
Box(modifier = Modifier.weight(0.3f)) {
// Hypothetical @Composable Image
Image(...)
}
}
}
Basically I am trying to load an image in a Box that will be weighted to 30% width of the display. The API I’m calling to fetch the image allows me to filter the url to only fetch the size of image I need. For example, if I’m fetching /images/pic1.jpg
but I only need it at max 400px width/height, I could fetch /images/pic1_400x400.jpg
. Is there any way for me to know the calculated width in pixels, so that I can pass this information along with my request?
Fwiw I don’t need to use Box exactly. If there’s another composable that would provide this behaviour, I can use that.
I guess my use case is similar to, say, if I were making a grid of images.
Thanks for any help!steelahhh
04/20/2021, 9:02 PMChris Fillmore
04/20/2021, 9:03 PMChris Fillmore
04/20/2021, 9:03 PMSean McQuillan [G]
04/20/2021, 9:07 PMTimo Drick
04/20/2021, 9:08 PMconstraints.maxWidth/maxHeight
It is the size in pixel. You can also get the size in dpColton Idle
04/20/2021, 9:34 PM@Composable
fun ImageFromUrl(imageUrl: String, modifier: Modifier = Modifier) {
CoilImage(
data = "",
contentDescription = null,
fadeIn = true,
modifier = modifier,
requestBuilder = { size: IntSize ->
val builder = MyUrlBuilder(width = size.width.toString(), height = size.width.toString())
data(builder.toUrl())
}
)
}
Chris Fillmore
04/21/2021, 1:10 AMcb
04/21/2021, 6:16 AMColton Idle
04/21/2021, 9:33 AMcb
04/21/2021, 6:30 PMwhat do you mean by constrained bounds?I mean that the bounds are constrained, i.e the parent has a maximum width, or you’ve set a explicit width/height. If the layout is set to wrap the content, you may get a size of
0,0
.Colton Idle
04/21/2021, 6:36 PMColton Idle
04/29/2021, 2:23 PMcb
04/29/2021, 3:07 PMrequestBuilder
is mostly meant for tweaking things like the placeholder, size, etc, rather than the URL. It probably does work for that, but it's not the intention, and not tested for thatColton Idle
04/29/2021, 3:27 PMColton Idle
04/29/2021, 7:29 PMcontentScale: ContentScale = ContentScale.Crop,
I don't understand why I need that if I have an aspectRatio of 16:9. I'm just going to accept it that I need ContentScale.Crop, but that doesn't make sense to me. If I don't do that then my imagesize was 1080 x 1080, but if I add the ContentScale.Crop it works as expected and I get a size of 1080 x 600.cb
04/30/2021, 6:33 AMcb
05/06/2021, 1:02 PMColton Idle
05/06/2021, 1:04 PM