您的位置:首页 > 移动开发 > Android开发

Android 获取设备的物理尺寸

2011-12-20 10:54 323 查看
得到设备的物理尺寸,注意,不是分辨率!从一个外国的帖子上找到的答案http://stackoverflow.com/questions/2193457/is-there-a-way-to-determine-android-physical-screen-height-in-cm-or-inches
    DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);double x = Math.pow(dm.widthPixels/dm.xdpi,2);double y = Math.pow(dm.heightPixels/dm.ydpi,2);double screenInches = Math.sqrt(x+y);Log.d("debug","Screen inches : " + screenInches);
[/code]还有一段:According to the documentation:The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thuson a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.This value does not exactly follow the real screen size (as given by xdpi and ydpi, but rather is used to scale the size of the overall UI in steps based on gross changes in the display dpi. For example, a 240x320 screen will have a density of 1 even ifits width is 1.8", 1.3", etc. However, if the screen resolution is increased to 320x480 but the screen size remained 1.5"x2" then the density would be increased (probably to 1.5).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: