# WidthSizeClass

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/sizeclass/WidthSizeClass.kt+class:androidx.test.espresso.device.sizeclass.WidthSizeClass)

*** ** * ** ***


```
public final class WidthSizeClass
```

<br />

*** ** * ** ***

A class to create buckets for the width of a window.

For details on window size classes, see https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes.

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion` |
| `public enum https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum>` |

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#COMPACT()` A bucket to represent a compact width window. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#EXPANDED()` A bucket to represent an expanded width window. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#MEDIUM()` A bucket to represent a medium width window. |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#compute(kotlin.Int)(int dpWidth)` Returns a recommended `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` for the width of a window given the width in DP. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#getEnum(androidx.test.espresso.device.sizeclass.WidthSizeClass)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass)` Returns a `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |
| `static final int` | `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass#getWidthDpInSizeClass(androidx.test.espresso.device.sizeclass.WidthSizeClass)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass)` Returns a recommended width of a window in DP given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |

## Public fields

### COMPACT

```
public static final @NonNull WidthSizeClass COMPACT
```

A bucket to represent a compact width window. One use-case is a phone in portrait.

### EXPANDED

```
public static final @NonNull WidthSizeClass EXPANDED
```

A bucket to represent an expanded width window. One use-case is a desktop app.

### MEDIUM

```
public static final @NonNull WidthSizeClass MEDIUM
```

A bucket to represent a medium width window. Some use-cases are a phone in landscape or a tablet.

## Public methods

### compute

```
public static final @NonNull WidthSizeClass compute(int dpWidth)
```

Returns a recommended `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` for the width of a window given the width in DP.

| Parameters |
|---|---|
| `int dpWidth` | the width of the window in DP |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass` | A recommended size class for the width |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the width is negative |

### getEnum

```
public static final @NonNull WidthSizeClass.Companion.WidthSizeClassEnum getEnum(@NonNull WidthSizeClass sizeClass)
```

Returns a `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass` | the size class |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` | the relevant WidthSizeClassEnum |

### getWidthDpInSizeClass

```
public static final int getWidthDpInSizeClass(@NonNull WidthSizeClass sizeClass)
```

Returns a recommended width of a window in DP given the `https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/espresso/device/sizeclass/WidthSizeClass sizeClass` | the size class |

| Returns |
|---|---|
| `int` | A recommended width in DP in this size class |