to top
Android APIs
public class

Display

extends Object
java.lang.Object
   ↳ android.view.Display

Class Overview

Provides information about the display size and density.

Summary

Constants
int DEFAULT_DISPLAY The default Display id.
Public Methods
void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize)
Return the range of display sizes an application can expect to encounter under normal operation, as long as there is no physical change in screen size.
int getDisplayId()
Returns the index of this display.
int getHeight()
This method is deprecated. Use getSize(Point) instead.
void getMetrics(DisplayMetrics outMetrics)
Gets display metrics that describe the size and density of this display.
int getOrientation()
This method is deprecated. use getRotation()
int getPixelFormat()
Return the native pixel format of the display.
void getRectSize(Rect outSize)
Gets the size of the display as a rectangle, in pixels.
float getRefreshRate()
Return the refresh rate of this display in frames per second.
int getRotation()
Returns the rotation of the screen from its "natural" orientation.
void getSize(Point outSize)
Gets the size of the display, in pixels.
int getWidth()
This method is deprecated. Use getSize(Point) instead.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_DISPLAY

Since: API Level 1

The default Display id.

Constant Value: 0 (0x00000000)

Public Methods

public void getCurrentSizeRange (Point outSmallestSize, Point outLargestSize)

Since: API Level 16

Return the range of display sizes an application can expect to encounter under normal operation, as long as there is no physical change in screen size. This is basically the sizes you will see as the orientation changes, taking into account whatever screen decoration there is in each rotation. For example, the status bar is always at the top of the screen, so it will reduce the height both in landscape and portrait, and the smallest height returned here will be the smaller of the two. This is intended for applications to get an idea of the range of sizes they will encounter while going through device rotations, to provide a stable UI through rotation. The sizes here take into account all standard system decorations that reduce the size actually available to the application: the status bar, navigation bar, system bar, etc. It does not take into account more transient elements like an IME soft keyboard.

Parameters
outSmallestSize Filled in with the smallest width and height that the application will encounter, in pixels (not dp units). The x (width) dimension here directly corresponds to Configuration.smallestScreenWidthDp, except the value here is in raw screen pixels rather than dp units. Your application may of course still get smaller space yet if, for example, a soft keyboard is being displayed.
outLargestSize Filled in with the largest width and height that the application will encounter, in pixels (not dp units). Your application may of course still get larger space than this if, for example, screen decorations like the status bar are being hidden.

public int getDisplayId ()

Since: API Level 1

Returns the index of this display. This is currently undefined; do not use.

public int getHeight ()

Since: API Level 1

This method is deprecated.
Use getSize(Point) instead.

public void getMetrics (DisplayMetrics outMetrics)

Since: API Level 1

Gets display metrics that describe the size and density of this display.

The size is adjusted based on the current rotation of the display.

The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decor elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays.

Parameters
outMetrics A DisplayMetrics object to receive the metrics.

public int getOrientation ()

Since: API Level 1

This method is deprecated.
use getRotation()

Returns
  • orientation of this display.

public int getPixelFormat ()

Since: API Level 1

Return the native pixel format of the display. The returned value may be one of the constants int PixelFormat.

public void getRectSize (Rect outSize)

Since: API Level 13

Gets the size of the display as a rectangle, in pixels.

Parameters
outSize A Rect object to receive the size information.
See Also

public float getRefreshRate ()

Since: API Level 1

Return the refresh rate of this display in frames per second.

public int getRotation ()

Since: API Level 8

Returns the rotation of the screen from its "natural" orientation. The returned value may be Surface.ROTATION_0 (no rotation), Surface.ROTATION_90, Surface.ROTATION_180, or Surface.ROTATION_270. For example, if a device has a naturally tall screen, and the user has turned it on its side to go into a landscape orientation, the value returned here may be either Surface.ROTATION_90 or Surface.ROTATION_270 depending on the direction it was turned. The angle is the rotation of the drawn graphics on the screen, which is the opposite direction of the physical rotation of the device. For example, if the device is rotated 90 degrees counter-clockwise, to compensate rendering will be rotated by 90 degrees clockwise and thus the returned value here will be Surface.ROTATION_90.

public void getSize (Point outSize)

Since: API Level 13

Gets the size of the display, in pixels.

Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size.

The size is adjusted based on the current rotation of the display.

The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decor elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays.

Parameters
outSize A Point object to receive the size information.

public int getWidth ()

Since: API Level 1

This method is deprecated.
Use getSize(Point) instead.