java.lang.Object | |
↳ | android.util.DisplayMetrics |
A structure describing general information about a display, such as its size, density, and font scaling.
To access the DisplayMetrics members, initialize an object like this:
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DENSITY_DEFAULT | The reference density used throughout the system. | |||||||||
int | DENSITY_HIGH | Standard quantized DPI for high-density screens. | |||||||||
int | DENSITY_LOW | Standard quantized DPI for low-density screens. | |||||||||
int | DENSITY_MEDIUM | Standard quantized DPI for medium-density screens. | |||||||||
int | DENSITY_TV | Standard quantized DPI for 720p TV screens. | |||||||||
int | DENSITY_XHIGH | Standard quantized DPI for extra-high-density screens. |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
density | The logical density of the display. | ||||||||||
densityDpi | The screen density expressed as dots-per-inch. | ||||||||||
heightPixels | The absolute height of the display in pixels. | ||||||||||
scaledDensity | A scaling factor for fonts displayed on the display. | ||||||||||
widthPixels | The absolute width of the display in pixels. | ||||||||||
xdpi | The exact physical pixels per inch of the screen in the X dimension. | ||||||||||
ydpi | The exact physical pixels per inch of the screen in the Y dimension. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a string containing a concise, human-readable description of this
object.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
The reference density used throughout the system.
Standard quantized DPI for high-density screens.
Standard quantized DPI for low-density screens.
Standard quantized DPI for medium-density screens.
Standard quantized DPI for 720p TV screens. Applications should
generally not worry about this density, instead targeting
DENSITY_XHIGH
for 1080p TV screens. For situations where
output is needed for a 720p screen, the UI elements can be scaled
automatically by the platform.
Standard quantized DPI for extra-high-density screens.
The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.
This value does not exactly follow the real screen size (as given by
xdpi
and ydpi
, but rather is used to scale the size of
the overall UI in steps based on gross changes in the display dpi. For
example, a 240x320 screen will have a density of 1 even if its width is
1.8", 1.3", etc. However, if the screen resolution is increased to
320x480 but the screen size remained 1.5"x2" then the density would be
increased (probably to 1.5).
The screen density expressed as dots-per-inch. May be either
DENSITY_LOW
, DENSITY_MEDIUM
, or DENSITY_HIGH
.
A scaling factor for fonts displayed on the display. This is the same
as density
, except that it may be adjusted in smaller
increments at runtime based on a user preference for the font size.
The exact physical pixels per inch of the screen in the X dimension.
The exact physical pixels per inch of the screen in the Y dimension.
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.