Get the screen's pixel dimensions

suggest change

To retrieve the screen's width and height in pixels, use the WindowManager display metrics.

// Get display metrics
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics);

These DisplayMetrics hold information about the device's screen, such as its density or size:

// Get width and height in pixels
Integer heightPixels = metrics.heightPixels;
Integer widthPixels = metrics.widthPixels;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents