`

获取屏幕分辨率 及 dp 和 像素关系

 
阅读更多
DisplayMetrics metric = new DisplayMetrics();  
        getWindowManager().getDefaultDisplay().getMetrics(metric);  
        int width = metric.widthPixels;     // 屏幕宽度(像素)  
        int height = metric.heightPixels;   // 屏幕高度(像素)  
        float density = metric.density;      // 屏幕密度(0.75 / 1.0 / 1.5)  
        int densityDpi = metric.densityDpi;  // 屏幕密度DPI(120 / 160 / 240)  

        Log.d("tiandandan", "width height density densityDpi" + width + " || " + height + " || " + density + " || " + densityDpi + " || ");
        System.out.println("width height density densityDpi" + width + " || " + height + " || " + density + " || " + densityDpi + " || ");

 

经过在960*540的屏幕实验

04-27 14:48:04.489: I/System.out(12361): width height density densityDpi540 || 960 || 1.5 || 240 ||

那么 屏幕的宽 的dp值为:

540 除以 1.5 = 360
那么控件设置360dp宽的话刚好铺满屏幕

哈哈~以此类推~

http://my.eoe.cn/xuliangbo/archive/3136.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics