Get screen size
- Home
- chevron_right
- Snippets
- chevron_right
- Get screen size
So if you ever need to get screen size in width and height on Android, you can use the following snippet:
/** * Returns the size of the screen in pixels (width and height) * * @return a Point that has the screen width stored in x and height in y */ public Point getScreenSize(Activity context) { Display display = context.getWindowManager().getDefaultDisplay(); Point size = new Point(); if (android.os.Build.VERSION.SDK_INT >= 13) { display.getSize(size); } else { //noinspection deprecation size.set(display.getWidth(), display.getHeight()); } return size; }