Android can be set to adjust the scaling ratio with the window size, but even so, the mobile phone program designer must still know the border of the mobile phone screen to avoid layout deformation caused by scaling.
The resolution information of the mobile phone is an important information of the mobile phone. It is good that android has provided the displaymetircs class to conveniently obtain the resolution. The displaymetics class is briefly introduced below:
The displaymetrics class under the andorid. util package provides general information about the display, such as the display size, resolution, and font.
To obtain displaymetrics members, first Initialize an object as follows:
Displaymetrics
Display = new displaymetrics ();
Log. D ("yujian <", display. tostring (); // output directly here. The information is 0.
Getwindowmanager (). getdefaultdisplay (). getmetrics (Display); // put some information about the current window in the displaymetrics class,
Log. D ("yujian <", display. tostring (); // you can use the dispalymetrics class to obtain information about the current window.
Note: The constructor displaymetrics does not need to pass any parameters. The getdefadisplay display () method stores the obtained wide and high dimensions in the displaymetrics object, the obtained width and height dimensions are measured in pixels. "pixels" refer to "absolute pixels" rather than "relative pixels ".
The displaymetrics tostring () method can be used to obtain most of displaymetrics's fields information. The following are some output information when the resolution is 480x320:
12-06 16:39:34. 946: D/yujian <(6731): displaymetrics
{Density = 1.0, width = 320, Height = 480, scaleddensity = 1.0,
Xdpi = 159.37254, ydpi = 160.42105}