Skip to content

Instantly share code, notes, and snippets.

@imandaliya
Created September 19, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imandaliya/f3e2175bd60dfd9a7b9ed967e2f869f2 to your computer and use it in GitHub Desktop.
Save imandaliya/f3e2175bd60dfd9a7b9ed967e2f869f2 to your computer and use it in GitHub Desktop.
// get Width and height of the screen
// this method only give available space for application screen
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
// get real height and width of the device
WindowManager windowManager =
(WindowManager) BaseApplication.getApplication().getSystemService(Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
Point outPoint = new Point();
if (Build.VERSION.SDK_INT >= 19) {
// include navigation bar
display.getRealSize(outPoint);
} else {
// exclude navigation bar
display.getSize(outPoint);
}
if (outPoint.y > outPoint.x) {
mRealSizeHeight = outPoint.y;
mRealSizeWidth = outPoint.x;
} else {
mRealSizeHeight = outPoint.x;
mRealSizeWidth = outPoint.y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment