Share via


Display.GetMetrics(DisplayMetrics) Method

Definition

Gets the size and density of this display.

[Android.Runtime.Register("getMetrics", "(Landroid/util/DisplayMetrics;)V", "GetGetMetrics_Landroid_util_DisplayMetrics_Handler")]
public virtual void GetMetrics (Android.Util.DisplayMetrics? outMetrics);
[<Android.Runtime.Register("getMetrics", "(Landroid/util/DisplayMetrics;)V", "GetGetMetrics_Landroid_util_DisplayMetrics_Handler")>]
abstract member GetMetrics : Android.Util.DisplayMetrics -> unit
override this.GetMetrics : Android.Util.DisplayMetrics -> unit

Parameters

outMetrics
DisplayMetrics

A DisplayMetrics object which receives the display metrics.

Attributes

Remarks

Gets the size and density of this display.

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

The returned size can also be different depending on the WindowManager associated with the display: <ul> <li>If metrics are requested from an activity (either using a WindowManager accessed by getWindowManager() or getSystemService(Context.WINDOW_SERVICE)), the returned metrics provide the size of the current app window. As a result, in multi-window mode, the returned size can be smaller than the size of the device screen. <li>If metrics are requested from a non-activity context (for example, the application context, where the WindowManager is accessed by getApplicationContext().getSystemService(Context.WINDOW_SERVICE)), the returned size can vary depending on API level: <ul> <li>API level 29 and below &mdash; The returned metrics provide the size of the entire display (based on current rotation) minus system decoration areas. <li>API level 30 and above &mdash; The returned metrics provide the size of the top running activity in the current process. If the current process has no running activities, the metrics provide the size of the default display of the device, including system decoration areas. </ul> </ul>

This member is deprecated. Use WindowMetrics#getBounds() to get the dimensions of the application window. Use WindowMetrics#getDensity() to get the density of the application window.

Java documentation for android.view.Display.getMetrics(android.util.DisplayMetrics).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to