Share via


WindowMetrics.Bounds Property

Definition

Returns the bounds of the area associated with this window or UiContext.

public Android.Graphics.Rect Bounds { [Android.Runtime.Register("getBounds", "()Landroid/graphics/Rect;", "", ApiSince=30)] get; }
[<get: Android.Runtime.Register("getBounds", "()Landroid/graphics/Rect;", "", ApiSince=30)>]
member this.Bounds : Android.Graphics.Rect

Property Value

window bounds in pixels.

Attributes

Remarks

Returns the bounds of the area associated with this window or UiContext.

<b>Note that the size of the reported bounds can have different size than Display#getSize(Point) based on your target API level and calling context.</b> This method reports the window size including all system bar areas, while Display#getSize(Point) can report the area excluding navigation bars and display cutout areas depending on the calling context and target SDK level. Please refer to Display#getSize(Point) for details.

The following code snippet shows how to get the bounds excluding navigation bars and display cutout:

final WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
            // Gets all excluding insets
            final WindowInsets windowInsets = metrics.getWindowInsets();
            Insets insets = windowInsets.getInsetsIgnoringVisibility(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);

</p>

Java documentation for android.view.WindowMetrics.getBounds().

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