如何获得屏幕尺寸?

时间:2013-04-23 18:00:18

标签: android

如何获取屏幕尺寸(以像素为单位)?我用了

Display display = getWindowManager().getDefaultDisplay(); 
Point size = new Point(); 
display.getSize(size);
int width = size.x; 
int height = size.y;`

但它不起作用......

2 个答案:

答案 0 :(得分:0)

使用此

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
int height = display.getHeight();

答案 1 :(得分:0)

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();     
int width = display.getWidth();
int height = display.getHeight();