Partager via


WindowMetrics.Bounds Property

Definition

Returns the bounds of the area associated with this window or android.annotation.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 android.annotation.UiContext.

<b>Note that the size of the reported bounds can have different size than Display#getSize(Point).</b> 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.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