---
title: "DpOffset"
description: "A two-dimensional offset using [Dp] for units.

To create a [DpOffset], call the top-level function that accepts an x/y pair of coordinates:
```
val offset = DpOffset(x, y)
```

The primary constructor of [DpOffset] is intended to be used with the [packedValue] property to
allow storing offsets in arrays or collections of primitives without boxing."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
value class DpOffset(val packedValue: Long)
```


A two-dimensional offset using `Dp` for units.

To create a `DpOffset`, call the top-level function that accepts an x/y pair of coordinates:
```
val offset = DpOffset(x, y)
```

The primary constructor of `DpOffset` is intended to be used with the `packedValue` property to
allow storing offsets in arrays or collections of primitives without boxing.

#### Parameters

| | |
| --- | --- |
| packedValue | `Long` value encoding the `x` and `y` components of the `DpOffset`. Encoded values can be obtained by using the `packedValue` property of existing `DpOffset` instances. |



## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val x: Dp
```


The horizontal aspect of the offset in `Dp`



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val y: Dp
```


The vertical aspect of the offset in `Dp`



## Functions

```kotlin
fun copy(x: Dp = this.x, y: Dp = this.y): DpOffset
```


Returns a copy of this `DpOffset` instance optionally overriding the x or y parameter


```kotlin
operator fun minus(other: DpOffset) =
        DpOffset(packFloats((x - other.x).value, (y - other.y).value))
```


Subtract a `DpOffset` from another one.


```kotlin
operator fun plus(other: DpOffset) =
        DpOffset(packFloats((x + other.x).value, (y + other.y).value))
```


Add a `DpOffset` to another one.


## Companion Object

#### Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val Zero = DpOffset(0x0L)
```


A `DpOffset` with 0 DP `x` and 0 DP `y` values.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val Unspecified = DpOffset(0x7fc00000_7fc00000L)
```


Represents an offset whose `x` and `y` are unspecified. This is usually a replacement for
`null` when a primitive value is desired. Access to `x` or `y` on an unspecified offset
is not allowed.





