Android get display size

Programming/Android 2013. 4. 22. 11:40 Posted by 생각하는로뎅
반응형

  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

  For the use case you're describing however a margin/padding in the layout seems more appropriate.

반응형

'Programming > Android' 카테고리의 다른 글

Android multi touch  (0) 2013.04.23
Android bitmap to jpeg (canvas)  (0) 2013.04.23
Android tabhost  (0) 2013.04.18
Android getting latitude and longitude by local  (0) 2013.04.17
Android XmlPullParser default  (0) 2013.04.17