Before Android 4.0, you can use the following method to obtain the screen width and height:
DisplayMetrics dm = new DisplayMetrics ();
GetWindowManager (). getDefaultDisplay (). getMetrics (dm );
Int mScreenW = dm. widthPixels; // obtain the width.
Int mScreenH = dm. heightPixels; // get the height
In the above method, before 4.0, the total width and total height of the screen are obtained, including the height of the status bar and the height of the navigation bar, such as a 480*800 device, the values obtained through the above method are 480 and 800, but the height obtained by the above method after 4.0 is the remaining height values except the navigation bar height, for example, if the height of the navigation bar is 48, the value of mScreenH obtained after 4.0 is 480-48 = 432.
Therefore, if you want to get the total height of the screen after 4.0, you need to use the following method:
Display display = getWindowManager (). getDefaultDisplay ();
Point point = new Point ();
Display. getRealSize (point );
Int mScreenH = point. y;
Int mScreenW = point. x;
The obtained width and height are 480 and 800.
Note: We are a car machine, so the size is the size of the horizontal screen.