Partager via


Configuration.ScreenWidthDp Property

Definition

The width of the available screen space in dp units.

[Android.Runtime.Register("screenWidthDp")]
public int ScreenWidthDp { get; set; }
[<Android.Runtime.Register("screenWidthDp")>]
member this.ScreenWidthDp : int with get, set

Property Value

Attributes

Remarks

The width of the available screen space in dp units.

"note"><b>Note:</b> If the app targets <c>android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM</c> or after, The width measurement reflects the window size without excluding insets. Otherwise, the measurement excludes window insets even when the app is displayed edge to edge using <c>android.view.Window#setDecorFitsSystemWindows(boolean) Window#setDecorFitsSystemWindows(boolean)</c>.</aside>

Use <c>android.view.WindowMetrics#getBounds()</c> to always obtain the horizontal display area available to an app or embedded activity including the area occupied by window insets. A version of the API is also available for use on older platforms through <c>androidx.window.layout.WindowMetrics</c>.

Corresponds to the available width resource qualifier. Defaults to #SCREEN_WIDTH_DP_UNDEFINED if no width is specified.

In multi-window mode, equals the width of the available display area of the app window, not the available display area of the device screen (for example, when apps are displayed side by side in split-screen mode in landscape orientation).

For embedded activities, equals the width of the individual activities, not the width of the app window or the device screen.

In multiple-screen scenarios, the width measurement can span screens. For example, if the app is spanning both screens of a dual-screen device (with the screens side by side), screenWidthDp represents the width of both screens excluding the area occupied by window insets. When the app is restricted to a single screen in a multiple-screen environment, screenWidthDp is the width of the screen on which the app is displayed excluding window insets.

If the app targets android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM or after, it is the same as android.view.WindowMetrics, but is expressed rounded to the nearest dp rather than px.

Otherwise, differs from android.view.WindowMetrics by not including window insets in the width measurement and by expressing the measurement in dp rather than px. Use screenWidthDp to obtain the width of the display area available to an app or embedded activity excluding the area occupied by window insets.

Java documentation for android.content.res.Configuration.screenWidthDp.

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