时间:2016年3月7日16:14:52
note:单位为像素。
三个方法中都是根据Display来进行测量。
- //方法一:
- WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
System.out.println("width = " + width + " , height = " + height);
//方法二:也可以获取到屏幕的密度density
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
int widthPixels = metrics.widthPixels;
int heightPixels = metrics.heightPixels;
System.out.println("width = " + widthPixels + " , height = " + heightPixels);
//方法三:
WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point point = new Point();
display.getSize(point);
int width = point.x;
int height = point.y;
System.out.println("width = " + width + " , height = " + height);
时间: 2024-10-08 04:48:55