An inch
or a mm
are unit of linear measurement on a surface, which could be a screen or a piece of paper.I'm strange if the result is not satisfactory for you.See this answer for more details.
How to define a line in centimeters in Android
-
31-05-2022 - |
Pregunta
I'm trying to define a line in Android which measure must be 10cm wide. I tried to put the width in mm and inches, but the results weren't satisfactory.
Also, I tried to follow this link: draw square 3x3 cm in Android
Desperately, i tried to measure 10cm in dip on the screen, but not is the same length in all screens
Is there any way to get it?
Thanks
Solución 4
Otros consejos
I think: height of screen (cm) / height resolution(pixel) * 3 = 3 cm height in pixel for that screen and resolution. width of the screen (cm) / width resoluzion(pixel) * 3 = 3 cm width in pixel for that screen and resolution.
Not sure about this.
REFER LINK TO GET dpi
nbpixel(1 inch) = densityDpi
so convert 1 cm to inch who give approximativly 0.4 inch
nbpixel(1cm) = 0.4 * densityDpi
So for make a ligne of one cm you must draw 0.4*DPI pixel
To draw a line of 1 cm, you must use multiple dpi (pixel density) to find the number of physical pixels. dpi/2.54
Mobile device displays also have something which is called devicePixelRatio. You might want to check that too. When building RealRuler (online ruler) I used to multiple mobile screen width/height with that ratio to get actual size. Not sure if it impacts actual size in cm in Android.
All this is very tricky.