标签:
获取屏幕的宽度与高度有以下几种方法:
1
、WindowManager wm = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
int
width = wm.getDefaultDisplay().getWidth();
int
height = wm.getDefaultDisplay().getHeight();
2
、WindowManager wm =
this
.getWindowManager();
int
width = wm.getDefaultDisplay().getWidth();
int
height = wm.getDefaultDisplay().getHeight();
3、 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)
标签:
原文地址:http://www.cnblogs.com/exmyth/p/4727545.html