Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/view/ScaleGestureDetector#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/view/ScaleGestureDetector#pubctors) \| [Methods](https://developer.android.com/reference/android/view/ScaleGestureDetector#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/ScaleGestureDetector#inhmethods)

# ScaleGestureDetector

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/view/ScaleGestureDetector "View this page in Kotlin") \|Java


`
public


class
ScaleGestureDetector
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.ScaleGestureDetector |

<br />

*** ** * ** ***

Detects scaling transformation gestures using the supplied `https://developer.android.com/reference/android/view/MotionEvent`s.
The `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` callback will notify users when a particular
gesture event has occurred.

This class should only be used with `https://developer.android.com/reference/android/view/MotionEvent`s reported via touch.

To use this class:

- Create an instance of the `ScaleGestureDetector` for your `https://developer.android.com/reference/android/view/View`
- In the `https://developer.android.com/reference/android/view/View#onTouchEvent(android.view.MotionEvent)` method ensure you call `https://developer.android.com/reference/android/view/ScaleGestureDetector#onTouchEvent(android.view.MotionEvent)`. The methods defined in your callback will be executed when the events occur.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` The listener for receiving notifications when gestures occur. |
| ` class` | `https://developer.android.com/reference/android/view/ScaleGestureDetector.SimpleOnScaleGestureListener` A convenience class to extend when you only want to listen for a subset of scaling-related events. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/ScaleGestureDetector#ScaleGestureDetector(android.content.Context,%20android.view.ScaleGestureDetector.OnScaleGestureListener)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener listener) ` Creates a ScaleGestureDetector with the supplied listener. |
| ` https://developer.android.com/reference/android/view/ScaleGestureDetector#ScaleGestureDetector(android.content.Context,%20android.view.ScaleGestureDetector.OnScaleGestureListener,%20android.os.Handler)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener listener, https://developer.android.com/reference/android/os/Handler handler) ` Creates a ScaleGestureDetector with the supplied listener. |

| ### Public methods ||
|---|---|
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getCurrentSpan()() ` Return the average distance between each of the pointers forming the gesture in progress through the focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getCurrentSpanX()() ` Return the average X distance between each of the pointers forming the gesture in progress through the focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getCurrentSpanY()() ` Return the average Y distance between each of the pointers forming the gesture in progress through the focal point. |
| ` long` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getEventTime()() ` Return the event time of the current event being processed. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getFocusX()() ` Get the X coordinate of the current gesture's focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getFocusY()() ` Get the Y coordinate of the current gesture's focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getPreviousSpan()() ` Return the previous average distance between each of the pointers forming the gesture in progress through the focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getPreviousSpanX()() ` Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getPreviousSpanY()() ` Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point. |
| ` float` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getScaleFactor()() ` Return the scaling factor from the previous scale event to the current event. |
| ` long` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#getTimeDelta()() ` Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#isInProgress()() ` Returns `true` if a scale gesture is in progress. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#isQuickScaleEnabled()() ` Return whether the quick scale gesture, in which the user performs a double tap followed by a swipe, should perform scaling. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#isStylusScaleEnabled()() ` Return whether the stylus scale gesture, in which the user uses a stylus and presses the button, should perform scaling. |
| ` boolean` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#onTouchEvent(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent event) ` Accepts MotionEvents and dispatches events to a `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` when appropriate. |
| ` void` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#setQuickScaleEnabled(boolean)(boolean scales) ` Set whether the associated `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` should receive onScale callbacks when the user performs a doubleTap followed by a swipe. |
| ` void` | ` https://developer.android.com/reference/android/view/ScaleGestureDetector#setStylusScaleEnabled(boolean)(boolean scales) ` Sets whether the associated `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` should receive onScale callbacks when the user uses a stylus and presses the button. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### ScaleGestureDetector

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScaleGestureDetector (Context context, 
                ScaleGestureDetector.OnScaleGestureListener listener)
```

Creates a ScaleGestureDetector with the supplied listener.
You may only use this constructor from a `https://developer.android.com/reference/android/os/Looper` thread.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the application's context. This value cannot be `null`. <br /> |
| `listener` | `ScaleGestureDetector.OnScaleGestureListener`: the listener invoked for all the callbacks, this must not be null. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `listener` is null. |

### ScaleGestureDetector

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ScaleGestureDetector (Context context, 
                ScaleGestureDetector.OnScaleGestureListener listener, 
                Handler handler)
```

Creates a ScaleGestureDetector with the supplied listener.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the application's context. This value cannot be `null`. <br /> |
| `listener` | `ScaleGestureDetector.OnScaleGestureListener`: the listener invoked for all the callbacks, this must not be null. <br /> |
| `handler` | `Handler`: the handler to use for running deferred listener events. This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `listener` is null. |

**See also:**

- `https://developer.android.com/reference/android/os/Handler#Handler()`

## Public methods

### getCurrentSpan

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getCurrentSpan ()
```

Return the average distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Distance between pointers in pixels. <br /> |

### getCurrentSpanX

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getCurrentSpanX ()
```

Return the average X distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Distance between pointers in pixels. <br /> |

### getCurrentSpanY

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getCurrentSpanY ()
```

Return the average Y distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Distance between pointers in pixels. <br /> |

### getEventTime

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getEventTime ()
```

Return the event time of the current event being processed.

<br />

| Returns ||
|---|---|
| `long` | Current event time in milliseconds. <br /> |

### getFocusX

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getFocusX ()
```

Get the X coordinate of the current gesture's focal point.
If a gesture is in progress, the focal point is between
each of the pointers forming the gesture.

If `https://developer.android.com/reference/android/view/ScaleGestureDetector#isInProgress()` would return false, the result of this
function is undefined.

<br />

| Returns ||
|---|---|
| `float` | X coordinate of the focal point in pixels. <br /> |

### getFocusY

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getFocusY ()
```

Get the Y coordinate of the current gesture's focal point.
If a gesture is in progress, the focal point is between
each of the pointers forming the gesture.

If `https://developer.android.com/reference/android/view/ScaleGestureDetector#isInProgress()` would return false, the result of this
function is undefined.

<br />

| Returns ||
|---|---|
| `float` | Y coordinate of the focal point in pixels. <br /> |

### getPreviousSpan

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getPreviousSpan ()
```

Return the previous average distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Previous distance between pointers in pixels. <br /> |

### getPreviousSpanX

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getPreviousSpanX ()
```

Return the previous average X distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Previous distance between pointers in pixels. <br /> |

### getPreviousSpanY

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getPreviousSpanY ()
```

Return the previous average Y distance between each of the pointers forming the
gesture in progress through the focal point.

<br />

| Returns ||
|---|---|
| `float` | Previous distance between pointers in pixels. <br /> |

### getScaleFactor

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getScaleFactor ()
```

Return the scaling factor from the previous scale event to the current
event. This value is defined as
(`https://developer.android.com/reference/android/view/ScaleGestureDetector#getCurrentSpan()` / `https://developer.android.com/reference/android/view/ScaleGestureDetector#getPreviousSpan()`).

<br />

| Returns ||
|---|---|
| `float` | The current scaling factor. <br /> |

### getTimeDelta

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getTimeDelta ()
```

Return the time difference in milliseconds between the previous
accepted scaling event and the current scaling event.

<br />

| Returns ||
|---|---|
| `long` | Time difference since the last scaling event in milliseconds. <br /> |

### isInProgress

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isInProgress ()
```

Returns `true` if a scale gesture is in progress.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isQuickScaleEnabled

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isQuickScaleEnabled ()
```

Return whether the quick scale gesture, in which the user performs a double tap followed by a
swipe, should perform scaling.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ScaleGestureDetector#setQuickScaleEnabled(boolean)`

### isStylusScaleEnabled

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isStylusScaleEnabled ()
```

Return whether the stylus scale gesture, in which the user uses a stylus and presses the
button, should perform scaling.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/ScaleGestureDetector#setStylusScaleEnabled(boolean)`

### onTouchEvent

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean onTouchEvent (MotionEvent event)
```

Accepts MotionEvents and dispatches events to a `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener`
when appropriate.

Applications should pass a complete and consistent event stream to this method.
A complete and consistent event stream involves all MotionEvents from the initial
ACTION_DOWN to the final ACTION_UP or ACTION_CANCEL.

<br />

<br />

| Parameters ||
|---|---|
| `event` | `MotionEvent`: The event to process. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the event was processed and the detector wants to receive the rest of the MotionEvents in this event stream. <br /> |

### setQuickScaleEnabled

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setQuickScaleEnabled (boolean scales)
```

Set whether the associated `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` should receive onScale callbacks
when the user performs a doubleTap followed by a swipe. Note that this is enabled by default
if the app targets API 19 and newer.

<br />

| Parameters ||
|---|---|
| `scales` | `boolean`: true to enable quick scaling, false to disable <br /> |

### setStylusScaleEnabled

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setStylusScaleEnabled (boolean scales)
```

Sets whether the associated `https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener` should receive
onScale callbacks when the user uses a stylus and presses the button.
Note that this is enabled by default if the app targets API 23 and newer.

<br />

| Parameters ||
|---|---|
| `scales` | `boolean`: true to enable stylus scaling, false to disable. <br /> |