OG
12/07/2021, 5:40 AMImage(modifier = Modifier.fillMaxWidth.aspectRatio(1.50f)
And I want to know the resolved height in px, and use that as an offset for another child composable. For simplicity, imagine this Image
is inside a Box
and there is another child composable in this box that I want to apply an offset too, by doing some calculation using the Image
height. (This problem would be easy if the height was hardcoded like 200.dp, but I have to use aspect ratio)
I'm guessing the only way to do this is using the Layout
composable where I would need to measure and layout everything manually... But wondering if there's a more simpler approach that I'm just overlooking. Thanks!Zoltan Demant
12/07/2021, 6:45 AMModifier.onSizeChanged { size ->
val itemHeight = with(density) {
val height = size.height
height.toDp()
}
}
Albert Chang
12/07/2021, 9:27 AMZach Klippenstein (he/him) [MOD]
12/07/2021, 4:05 PMAlignment
, which lets you write positioning logic in terms of sizes but without writing a whole custom layout: https://developer.android.com/reference/kotlin/androidx/compose/ui/Alignment#align(androidx.compose.ui.unit.IntSize,androidx.compose.ui.unit.IntSize,androidx.compose.ui.unit.LayoutDirection)OG
12/07/2021, 5:30 PMBoxWithConstraints
gets the job done, since if we know the full width of the screen we can calculate the height right away using the same aspect ratio passed to the Image