I have a composable in which I have to calculate t...
# compose-android
m
I have a composable in which I have to calculate the height and width that is available for that composable..I am setting its size from caller. It has a modifier params to which I am calling as modifier.fillMaxWidth().fillMaxHeight(.5f) I need the height to calculate the bars of my music player.
Tried Approach - Use the hoisted height variable and Calculate the size on GloballyChanged and set the value to hoisted height variable . The problem is that I have a canvas and I need to draw bars in the canvas depeending on the height that is available to the composable
Bars doesn;t seem to draw and it appears blank
k
Canvas draw block gets
size
from which you can get current width and height
m
You will be surprised to know that the height of the canvas is coming out be 3x the height of the BoxWithContainer that contains it... Any Idea why?
image.png
k
No code - no way to know where the problem is
It’s not exactly 3x, but it may be a very specific density of the device - since you’re having one height in
dp
units and another (canvas) in pixels
m
Yeah you are right
k
What exactly are you asking to look at? Canvas reports its size in pixels, and up top you report the height of the screen in
dp
units
m
Understood about canvas. When I called
Copy code
val canvasHeight = size.height.toDp().value
The height of canvas is coming out to be proper for the calculations that I need... Thanks🙌
👍 1
👍🏾 1
103 Views