# 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)

*** ** * ** ***


```
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 |
|---|
| `object https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion` |
| `enum https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum>` |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#compute(kotlin.Int)(dpWidth: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns a recommended `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` for the width of a window given the width in DP. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#getEnum(androidx.test.espresso.device.sizeclass.WidthSizeClass)(sizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass)` Returns a `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass.Companion.WidthSizeClassEnum` given the `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#getWidthDpInSizeClass(androidx.test.espresso.device.sizeclass.WidthSizeClass)(sizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass)` Returns a recommended width of a window in DP given the `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass`. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#COMPACT()` A bucket to represent a compact width window. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#EXPANDED()` A bucket to represent an expanded width window. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass#MEDIUM()` A bucket to represent a medium width window. |

## Public companion functions

### compute

```
fun compute(dpWidth: Int): WidthSizeClass
```

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

| Parameters |
|---|---|
| `dpWidth: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the width of the window in DP |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/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

```
fun getEnum(sizeClass: WidthSizeClass): WidthSizeClass.Companion.WidthSizeClassEnum
```

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

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

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

### getWidthDpInSizeClass

```
fun getWidthDpInSizeClass(sizeClass: WidthSizeClass): Int
```

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

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A recommended width in DP in this size class |

## Public companion properties

### COMPACT

```
val COMPACT: WidthSizeClass
```

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

### EXPANDED

```
val EXPANDED: WidthSizeClass
```

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

### MEDIUM

```
val MEDIUM: WidthSizeClass
```

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