DisplayMetrics
open class DisplayMetrics
| kotlin.Any | |
| ↳ | android.util.DisplayMetrics |
A structure describing general information about a display, such as its size, density, and font scaling.
To access the DisplayMetrics members, retrieve display metrics like this:
context.getResources().getDisplayMetrics();
For UI layout, obtain android.view.WindowMetrics from WindowManager.getCurrentWindowMetrics(). DisplayMetrics should only be used for obtaining display related properties, such as xdpi and ydpi
See density for more information about the differences between xdpi, ydpi and density.
Summary
| Constants | |
|---|---|
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
Intermediate density for screens that sit somewhere between |
| static Int |
The reference density used throughout the system. |
| static Int |
Standard quantized DPI for high-density screens. |
| static Int |
Standard quantized DPI for low-density screens. |
| static Int |
Standard quantized DPI for medium-density screens. |
| static Int |
This is a secondary density, added for some common screen configurations. |
| static Int |
Standard quantized DPI for extra-high-density screens. |
| static Int |
Standard quantized DPI for extra-extra-high-density screens. |
| static Int |
Standard quantized DPI for extra-extra-extra-high-density screens. |
| Public constructors | |
|---|---|
| Public methods | |
|---|---|
| open Boolean |
equals(other: DisplayMetrics!)Returns true if these display metrics equal the other display metrics. |
| open Boolean |
Indicates whether some other object is "equal to" this one. |
| open Int |
hashCode() |
| open Unit |
setTo(o: DisplayMetrics!) |
| open Unit | |
| open String |
toString() |
| Properties | |
|---|---|
| static Int |
The device's stable density. |
| Float |
The logical density of the display. |
| Int |
The screen density expressed as dots-per-inch. |
| Int |
The absolute height of the available display size in pixels. |
| Float |
A scaling factor for fonts displayed on the display. |
| Int |
The absolute width of the available display size in pixels. |
| Float |
The exact physical pixels per inch of the screen in the X dimension. |
| Float |
The exact physical pixels per inch of the screen in the Y dimension. |
Constants
DENSITY_140
static val DENSITY_140: Int
Intermediate density for screens that sit between DENSITY_LOW (120dpi) and DENSITY_MEDIUM (160dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_MEDIUM assets for them.
Value: 140DENSITY_180
static val DENSITY_180: Int
Intermediate density for screens that sit between DENSITY_MEDIUM (160dpi) and DENSITY_HIGH (240dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_HIGH assets for them.
Value: 180DENSITY_200
static val DENSITY_200: Int
Intermediate density for screens that sit between DENSITY_MEDIUM (160dpi) and DENSITY_HIGH (240dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_HIGH assets for them.
Value: 200DENSITY_220
static val DENSITY_220: Int
Intermediate density for screens that sit between DENSITY_MEDIUM (160dpi) and DENSITY_HIGH (240dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_HIGH assets for them.
Value: 220DENSITY_260
static val DENSITY_260: Int
Intermediate density for screens that sit between DENSITY_HIGH (240dpi) and DENSITY_XHIGH (320dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XHIGH assets for them.
Value: 260DENSITY_280
static val DENSITY_280: Int
Intermediate density for screens that sit between DENSITY_HIGH (240dpi) and DENSITY_XHIGH (320dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XHIGH assets for them.
Value: 280DENSITY_300
static val DENSITY_300: Int
Intermediate density for screens that sit between DENSITY_HIGH (240dpi) and DENSITY_XHIGH (320dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XHIGH assets for them.
Value: 300DENSITY_340
static val DENSITY_340: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 340DENSITY_360
static val DENSITY_360: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 360DENSITY_390
static val DENSITY_390: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 390DENSITY_400
static val DENSITY_400: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 400DENSITY_420
static val DENSITY_420: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 420DENSITY_440
static val DENSITY_440: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 440DENSITY_450
static val DENSITY_450: Int
Intermediate density for screens that sit somewhere between DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXHIGH assets for them.
Value: 450DENSITY_520
static val DENSITY_520: Int
Intermediate density for screens that sit somewhere between DENSITY_XXHIGH (480 dpi) and DENSITY_XXXHIGH (640 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXXHIGH assets for them.
Value: 520DENSITY_560
static val DENSITY_560: Int
Intermediate density for screens that sit somewhere between DENSITY_XXHIGH (480 dpi) and DENSITY_XXXHIGH (640 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXXHIGH assets for them.
Value: 560DENSITY_600
static val DENSITY_600: Int
Intermediate density for screens that sit somewhere between DENSITY_XXHIGH (480 dpi) and DENSITY_XXXHIGH (640 dpi). This is not a density that applications should target, instead relying on the system to scale their DENSITY_XXXHIGH assets for them.
Value: 600DENSITY_DEFAULT
static val DENSITY_DEFAULT: Int
The reference density used throughout the system.
Value: 160DENSITY_HIGH
static val DENSITY_HIGH: Int
Standard quantized DPI for high-density screens.
Value: 240DENSITY_LOW
static val DENSITY_LOW: Int
Standard quantized DPI for low-density screens.
Value: 120DENSITY_MEDIUM
static val DENSITY_MEDIUM: Int
Standard quantized DPI for medium-density screens.
Value: 160DENSITY_TV
static val DENSITY_TV: Int
This is a secondary density, added for some common screen configurations. It is recommended that applications not generally target this as a first class density -- that is, don't supply specific graphics for this density, instead allow the platform to scale from other densities (typically DENSITY_HIGH) as appropriate. In most cases (such as using bitmaps in android.graphics.drawable.Drawable) the platform can perform this scaling at load time, so the only cost is some slight startup runtime overhead.
This density was original introduced to correspond with a 720p TV screen: the density for 1080p televisions is DENSITY_XHIGH, and the value here provides the same UI size for a TV running at 720p. It has also found use in 7" tablets, when these devices have 1280x720 displays.
Value: 213DENSITY_XHIGH
static val DENSITY_XHIGH: Int
Standard quantized DPI for extra-high-density screens.
Value: 320DENSITY_XXHIGH
static val DENSITY_XXHIGH: Int
Standard quantized DPI for extra-extra-high-density screens.
Value: 480DENSITY_XXXHIGH
static val DENSITY_XXXHIGH: Int
Standard quantized DPI for extra-extra-extra-high-density screens. Applications should not generally worry about this density; relying on XHIGH graphics being scaled up to it should be sufficient for almost all cases. A typical use of this density would be 4K television screens -- 3840x2160, which is 2x a traditional HD 1920x1080 screen which runs at DENSITY_XHIGH.
Value: 640Public constructors
Public methods
equals
open fun equals(other: DisplayMetrics!): Boolean
Returns true if these display metrics equal the other display metrics.
| Parameters | |
|---|---|
other |
DisplayMetrics!: The display metrics with which to compare. |
| Return | |
|---|---|
Boolean |
True if the display metrics are equal. |
equals
open fun equals(other: Any?): Boolean
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| Parameters | |
|---|---|
obj |
the reference object with which to compare. |
o |
This value may be null. |
| Return | |
|---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
hashCode
open fun hashCode(): Int
| Return | |
|---|---|
Int |
a hash code value for this object. |
toString
open fun toString(): String
| Return | |
|---|---|
String |
a string representation of the object. |
Properties
DENSITY_DEVICE_STABLE
static val DENSITY_DEVICE_STABLE: Int
The device's stable density.
This value is constant at run time and may not reflect the current display density. To obtain the current density for a specific display, use densityDpi.
density
var density: Float
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).
See Also
densityDpi
var densityDpi: Int
The screen density expressed as dots-per-inch. May be any one of the DENSITY_ constants defined above. New constants are frequently added, and constants added on new Android versions may be backported to previous Android versions, so applications should not strongly rely on density matching one of the enum constants.
Value is android.util.DisplayMetrics#DENSITY_LOW, android.util.DisplayMetrics#DENSITY_140, android.util.DisplayMetrics#DENSITY_MEDIUM, android.util.DisplayMetrics#DENSITY_180, android.util.DisplayMetrics#DENSITY_200, android.util.DisplayMetrics#DENSITY_TV, android.util.DisplayMetrics#DENSITY_220, android.util.DisplayMetrics#DENSITY_HIGH, android.util.DisplayMetrics#DENSITY_260, android.util.DisplayMetrics#DENSITY_280, android.util.DisplayMetrics#DENSITY_300, android.util.DisplayMetrics#DENSITY_XHIGH, android.util.DisplayMetrics#DENSITY_340, android.util.DisplayMetrics#DENSITY_360, android.util.DisplayMetrics#DENSITY_390, android.util.DisplayMetrics#DENSITY_400, android.util.DisplayMetrics#DENSITY_420, android.util.DisplayMetrics#DENSITY_440, android.util.DisplayMetrics#DENSITY_450, android.util.DisplayMetrics#DENSITY_XXHIGH, android.util.DisplayMetrics#DENSITY_520, android.util.DisplayMetrics#DENSITY_560, android.util.DisplayMetrics#DENSITY_600, or android.util.DisplayMetrics#DENSITY_XXXHIGH
heightPixels
var heightPixels: Int
The absolute height of the available display size in pixels.
scaledDensity
varscaledDensity: Float
Deprecated: this scalar factor is no longer accurate due to adaptive non-linear font scaling. Please use TypedValue.applyDimension(int, float, DisplayMetrics) or TypedValue.deriveDimension(int, float, DisplayMetrics) to convert between SP font sizes and pixels.
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.
widthPixels
var widthPixels: Int
The absolute width of the available display size in pixels.
xdpi
var xdpi: Float
The exact physical pixels per inch of the screen in the X dimension.
ydpi
var ydpi: Float
The exact physical pixels per inch of the screen in the Y dimension.