public class DisplayMetrics extends Object
To access the DisplayMetrics members, initialize an object like this:
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
Modifier and Type | Field and Description |
---|---|
float |
density
The logical density of the display.
|
static int |
DENSITY_260
Intermediate density for screens that sit between
DENSITY_HIGH (240dpi) and
DENSITY_XHIGH (320dpi). |
static int |
DENSITY_280
Intermediate density for screens that sit between
DENSITY_HIGH (240dpi) and
DENSITY_XHIGH (320dpi). |
static int |
DENSITY_300
Intermediate density for screens that sit between
DENSITY_HIGH (240dpi) and
DENSITY_XHIGH (320dpi). |
static int |
DENSITY_340
Intermediate density for screens that sit somewhere between
DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). |
static int |
DENSITY_360
Intermediate density for screens that sit somewhere between
DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). |
static int |
DENSITY_400
Intermediate density for screens that sit somewhere between
DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). |
static int |
DENSITY_420
Intermediate density for screens that sit somewhere between
DENSITY_XHIGH (320 dpi) and DENSITY_XXHIGH (480 dpi). |
static int |
DENSITY_560
Intermediate density for screens that sit somewhere between
DENSITY_XXHIGH (480 dpi) and DENSITY_XXXHIGH (640 dpi). |
static int |
DENSITY_DEFAULT
The reference density used throughout the system.
|
static float |
DENSITY_DEFAULT_SCALE
Scaling factor to convert a density in DPI units to the density scale.
|
static int |
DENSITY_DEVICE
Deprecated.
Use
DENSITY_DEVICE_STABLE to obtain the stable
device density or densityDpi to obtain the current
density for a specific display. |
static int |
DENSITY_DEVICE_STABLE
The device's stable density.
|
static int |
DENSITY_HIGH
Standard quantized DPI for high-density screens.
|
static int |
DENSITY_LOW
Standard quantized DPI for low-density screens.
|
static int |
DENSITY_MEDIUM
Standard quantized DPI for medium-density screens.
|
static int |
DENSITY_TV
This is a secondary density, added for some common screen configurations.
|
static int |
DENSITY_XHIGH
Standard quantized DPI for extra-high-density screens.
|
static int |
DENSITY_XXHIGH
Standard quantized DPI for extra-extra-high-density screens.
|
static int |
DENSITY_XXXHIGH
Standard quantized DPI for extra-extra-extra-high-density screens.
|
int |
densityDpi
The screen density expressed as dots-per-inch.
|
int |
heightPixels
The absolute height of the available display size in pixels.
|
float |
noncompatDensity
The reported display density prior to any compatibility mode scaling
being applied.
|
int |
noncompatDensityDpi
The reported display density prior to any compatibility mode scaling
being applied.
|
int |
noncompatHeightPixels
The reported display height prior to any compatibility mode scaling
being applied.
|
float |
noncompatScaledDensity
The reported scaled density prior to any compatibility mode scaling
being applied.
|
int |
noncompatWidthPixels
The reported display width prior to any compatibility mode scaling
being applied.
|
float |
noncompatXdpi
The reported display xdpi prior to any compatibility mode scaling
being applied.
|
float |
noncompatYdpi
The reported display ydpi prior to any compatibility mode scaling
being applied.
|
float |
scaledDensity
A scaling factor for fonts displayed on the display.
|
int |
widthPixels
The absolute width of the available display size in pixels.
|
float |
xdpi
The exact physical pixels per inch of the screen in the X dimension.
|
float |
ydpi
The exact physical pixels per inch of the screen in the Y dimension.
|
Constructor and Description |
---|
DisplayMetrics() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(DisplayMetrics other)
Returns true if these display metrics equal the other display metrics.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
boolean |
equalsPhysical(DisplayMetrics other)
Returns true if the physical aspects of the two display metrics
are equal.
|
int |
hashCode()
Returns a hash code value for the object.
|
void |
setTo(DisplayMetrics o) |
void |
setToDefaults() |
String |
toString()
Returns a string representation of the object.
|
public static final int DENSITY_LOW
public static final int DENSITY_MEDIUM
public static final int DENSITY_TV
DENSITY_HIGH
) as
appropriate. In most cases (such as using bitmaps in
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.
public static final int DENSITY_HIGH
public static final int DENSITY_260
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.public static final int DENSITY_280
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.public static final int DENSITY_300
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.public static final int DENSITY_XHIGH
public static final int DENSITY_340
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.public static final int DENSITY_360
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.public static final int DENSITY_400
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.public static final int DENSITY_420
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.public static final int DENSITY_XXHIGH
public static final int DENSITY_560
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.public static final int DENSITY_XXXHIGH
public static final int DENSITY_DEFAULT
public static final float DENSITY_DEFAULT_SCALE
@Deprecated public static int DENSITY_DEVICE
DENSITY_DEVICE_STABLE
to obtain the stable
device density or densityDpi
to obtain the current
density for a specific display.
This value reflects any changes made to the device density. To obtain
the device's stable density, use DENSITY_DEVICE_STABLE
.
public static final int DENSITY_DEVICE_STABLE
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
.
public int widthPixels
public int heightPixels
public float density
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).
DENSITY_DEFAULT
public int densityDpi
DENSITY_LOW
, DENSITY_MEDIUM
, or DENSITY_HIGH
.public float scaledDensity
density
, except that it may be adjusted in smaller
increments at runtime based on a user preference for the font size.public float xdpi
public float ydpi
public int noncompatWidthPixels
public int noncompatHeightPixels
public float noncompatDensity
public int noncompatDensityDpi
public float noncompatScaledDensity
public float noncompatXdpi
public float noncompatYdpi
public void setTo(DisplayMetrics o)
public void setToDefaults()
public boolean equals(Object o)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
o
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public boolean equals(DisplayMetrics other)
other
- The display metrics with which to compare.public boolean equalsPhysical(DisplayMetrics other)
other
- The display metrics with which to compare.public int hashCode()
Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())