display getSize()

If you want the the display dimensions in pixels you can use getSize: 

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

If you're not in an Activity you can get the default Display via WINDOW_SERVICE: 

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); 
Display display = wm.getDefaultDisplay(); 

Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated: 

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

posted @ 2015-01-13 18:50  cateatmycode  阅读(396)  评论(0编辑  收藏  举报