Get the screen's pixel dimensions
suggest changeTo 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;
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents