How can I detect the screen size of a android phone in inches?getSize method returns size from pixels ,but when adapting to different screen sizes it not work.There are screen with same pixel size but smaller in inches,in that case some views not get required space in screen.If can't get size in inches can do same thing using pixel size?
-
1If you haven't already, you should probably read http://developer.android.com/training/multiscreen/index.html – FunkTheMonk Sep 06 '13 at 07:59
-
A previous post on a similar issue might help http://stackoverflow.com/questions/5015094/determine-device-screen-category-small-normal-large-xlarge-using-code – AurA Sep 06 '13 at 07:59
-
Already asked here : [Is there a way to determine android physical screen height in cm or inches][1] [1]: http://stackoverflow.com/questions/2193457/is-there-a-way-to-determine-android-physical-screen-height-in-cm-or-inches – Kyu_ Sep 06 '13 at 08:01
1 Answers
You will be getting pixels right convert to inches by,,,
To get the size of a lets say how much 1pixel = x inches. Ask the person to get a ruler and put it on the screen and measure the width of a line e.g. 320 pixel's line. Then you'll know 320pixels = x inches, given x 320/x = 1 inch.
Or
For your map just let x pixels = y inches and the map would be scaled vertically and horizontally by different factors the person would have a good idea in size provided you show a horizontal and vertical scale.
Edit
Hey I got a better way to do this, but it doesn't work when the screen does not fill the entire monitor (commonly on CRT monitors). Just ask for the size of the monitor the person is using and your set with everything you need. The ratios of 1024x768, 800x600, 640x480 are all 4/3, so is the height and width of the physical monitor. 15" monitors go up by 9" and left by 12". so the height in pixels is split evenly in 9" and width is split evenly in 12". Therefore:
x_screen_resolution = 12"
y_screen_resolution = 9"
Now you have your conversion factor from pixels to inches for a 15" monitor. The ratio 4/3 is probably a standard so if you get in inches Z of the size of the monitor then
x*x + y*y = Z*Z ... eq1
x/y = 4/3 .... eq2
x = 4y/3 ...
16yy/9 + yy = ZZ
25yy/16 = 9ZZ/16
yy = 9ZZ/25
-------------
y = 3Z/5
We now know y solve for screen width x
x = sqrt(ZZ-yy)
and thus
x_screen_resolution = x inches
y_screen_resolution = y inches
hope it helps