# Print output for @column tags ?> WindowMetrics - Android SDK | Android Developers

Most visited

Recently visited

WindowMetrics

public final class WindowMetrics
extends Object

java.lang.Object
   ↳ android.view.WindowMetrics


Metrics about a Window, consisting of the bounds and WindowInsets.

This is usually obtained from WindowManager#getCurrentWindowMetrics() and WindowManager#getMaximumWindowMetrics().

See also:

Summary

Public constructors

WindowMetrics(Rect bounds, WindowInsets windowInsets)

Public methods

Rect getBounds()

Returns the bounds of the area associated with this window or visual context.

WindowInsets getWindowInsets()

Returns the WindowInsets of the area associated with this window or visual context.

Inherited methods

Public constructors

WindowMetrics

public WindowMetrics (Rect bounds, 
                WindowInsets windowInsets)

Parameters
bounds Rect: This value cannot be null.

windowInsets WindowInsets: This value cannot be null.

Public methods

getBounds

public Rect getBounds ()

Returns the bounds of the area associated with this window or visual context.

Note that the size of the reported bounds can have different size than Display#getSize(Point). This method reports the window size including all system bar areas, while Display#getSize(Point) reports the area excluding navigation bars and display cutout areas. The value reported by Display#getSize(Point) can be obtained by using:

 final WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
 // Gets all excluding insets
 final WindowInsets windowInsets = metrics.getWindowInsets();
 Insets insets = windowInsets.getInsetsIgnoreVisibility(WindowInsets.Type.navigationBars()
         | WindowInsets.Type.displayCutout());

 int insetsWidth = insets.right + insets.left;
 int insetsHeight = insets.top + insets.bottom;

 // Legacy size that Display#getSize reports
 final Rect bounds = metrics.getBounds();
 final Size legacySize = new Size(bounds.width() - insetsWidth,
         bounds.height() - insetsHeight);
 

Returns
Rect window bounds in pixels. This value cannot be null.

getWindowInsets

public WindowInsets getWindowInsets ()

Returns the WindowInsets of the area associated with this window or visual context.

Returns
WindowInsets the WindowInsets of the visual area. This value cannot be null.