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宽的话刚好铺满屏幕
哈哈~以此类推~