Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/android/widget/EdgeEffect#lfields) \| [Ctors](https://developer.android.com/reference/android/widget/EdgeEffect#pubctors) \| [Methods](https://developer.android.com/reference/android/widget/EdgeEffect#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/widget/EdgeEffect#inhmethods)

# EdgeEffect

*** ** * ** ***

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


`
public


class
EdgeEffect
`


`

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


`

`


`

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

<br />

*** ** * ** ***

This class performs the graphical effect used at the edges of scrollable widgets
when the user scrolls beyond the content bounds in 2D space.

EdgeEffect is stateful. Custom widgets using EdgeEffect should create an
instance for each edge that should show the effect, feed it input data using
the methods `https://developer.android.com/reference/android/widget/EdgeEffect#onAbsorb(int)`, `https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float)`, and `https://developer.android.com/reference/android/widget/EdgeEffect#onRelease()`,
and draw the effect using `https://developer.android.com/reference/android/widget/EdgeEffect#draw(android.graphics.Canvas)` in the widget's overridden
`https://developer.android.com/reference/android/view/View#draw(android.graphics.Canvas)` method. If `https://developer.android.com/reference/android/widget/EdgeEffect#isFinished()` returns
false after drawing, the edge effect's animation is not yet complete and the widget
should schedule another drawing pass to continue the animation.

When drawing, widgets should draw their main content and child views first,
usually by invoking `super.draw(canvas)` from an overridden `draw`
method. (This will invoke onDraw and dispatch drawing to child views as needed.)
The edge effect may then be drawn on top of the view's content using the
`https://developer.android.com/reference/android/widget/EdgeEffect#draw(android.graphics.Canvas)` method.

<br />

## Summary

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/graphics/BlendMode` | `https://developer.android.com/reference/android/widget/EdgeEffect#DEFAULT_BLEND_MODE` The default blend mode used by `https://developer.android.com/reference/android/widget/EdgeEffect`. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/widget/EdgeEffect#EdgeEffect(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Construct a new EdgeEffect with a theme appropriate for the provided context. |
| ` https://developer.android.com/reference/android/widget/EdgeEffect#EdgeEffect(android.content.Context,%20android.util.AttributeSet)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs) ` Construct a new EdgeEffect with a theme appropriate for the provided context. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/widget/EdgeEffect#draw(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` Draw into the provided canvas. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#finish()() ` Immediately finish the current animation. |
| ` https://developer.android.com/reference/android/graphics/BlendMode` | ` https://developer.android.com/reference/android/widget/EdgeEffect#getBlendMode()() ` Returns the blend mode. |
| ` int` | ` https://developer.android.com/reference/android/widget/EdgeEffect#getColor()() ` Return the color of this edge effect in argb. |
| ` float` | ` https://developer.android.com/reference/android/widget/EdgeEffect#getDistance()() ` Returns the pull distance needed to be released to remove the showing effect. |
| ` int` | ` https://developer.android.com/reference/android/widget/EdgeEffect#getMaxHeight()() ` Return the maximum height that the edge effect will be drawn at given the original `https://developer.android.com/reference/android/widget/EdgeEffect#setSize(int,%20int)`. |
| ` boolean` | ` https://developer.android.com/reference/android/widget/EdgeEffect#isFinished()() ` Reports if this EdgeEffect's animation is finished. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#onAbsorb(int)(int velocity) ` Call when the effect absorbs an impact at the given velocity. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float)(float deltaDistance) ` A view should call this when content is pulled away from an edge by the user. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float,%20float)(float deltaDistance, float displacement) ` A view should call this when content is pulled away from an edge by the user. |
| ` float` | ` https://developer.android.com/reference/android/widget/EdgeEffect#onPullDistance(float,%20float)(float deltaDistance, float displacement) ` A view should call this when content is pulled away from an edge by the user. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#onRelease()() ` Call when the object is released after being pulled. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#setBlendMode(android.graphics.BlendMode)(https://developer.android.com/reference/android/graphics/BlendMode blendmode) ` Set or clear the blend mode. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#setColor(int)(int color) ` Set the color of this edge effect in argb. |
| ` void` | ` https://developer.android.com/reference/android/widget/EdgeEffect#setSize(int,%20int)(int width, int height) ` Set the size of this edge effect in pixels. |

| ### 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*. | ||

## Fields

### DEFAULT_BLEND_MODE

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

```
public static final BlendMode DEFAULT_BLEND_MODE
```

The default blend mode used by `https://developer.android.com/reference/android/widget/EdgeEffect`.

<br />

## Public constructors

### EdgeEffect

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

```
public EdgeEffect (Context context)
```

Construct a new EdgeEffect with a theme appropriate for the provided context.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: Context used to provide theming and resource information for the EdgeEffect <br /> |

### EdgeEffect

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

```
public EdgeEffect (Context context, 
                AttributeSet attrs)
```

Construct a new EdgeEffect with a theme appropriate for the provided context.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: Context used to provide theming and resource information for the EdgeEffect. This value cannot be `null`. <br /> |
| `attrs` | `AttributeSet`: The attributes of the XML tag that is inflating the view. This value may be `null`. <br /> |

## Public methods

### draw

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

```
public boolean draw (Canvas canvas)
```

Draw into the provided canvas. Assumes that the canvas has been rotated
accordingly and the size has been set. The effect will be drawn the full
width of X=0 to X=width, beginning from Y=0 and extending to some factor \<
1.f of height. The effect will only be visible on a
hardware canvas, e.g. `https://developer.android.com/reference/android/graphics/RenderNode#beginRecording()`.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: Canvas to draw into <br /> |

| Returns ||
|---|---|
| `boolean` | true if drawing should continue beyond this frame to continue the animation <br /> |

### finish

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

```
public void finish ()
```

Immediately finish the current animation.
After this call `https://developer.android.com/reference/android/widget/EdgeEffect#isFinished()` will return true.

<br />

### getBlendMode

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

```
public BlendMode getBlendMode ()
```

Returns the blend mode. A blend mode defines how source pixels
(generated by a drawing command) are composited with the destination pixels
(content of the render target).

<br />

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/BlendMode` | BlendMode. This value may be `null`. <br /> |

### getColor

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

```
public int getColor ()
```

Return the color of this edge effect in argb.

<br />

| Returns ||
|---|---|
| `int` | The color of this edge effect in argb <br /> |

### getDistance

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

```
public float getDistance ()
```

Returns the pull distance needed to be released to remove the showing effect.
It is determined by the `https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float,%20float)` `deltaDistance` and
any animating values, including from `https://developer.android.com/reference/android/widget/EdgeEffect#onAbsorb(int)` and `https://developer.android.com/reference/android/widget/EdgeEffect#onRelease()`.

This can be used in conjunction with `https://developer.android.com/reference/android/widget/EdgeEffect#onPullDistance(float,%20float)` to
release the currently showing effect.

<br />

| Returns ||
|---|---|
| `float` | The pull distance that must be released to remove the showing effect. <br /> |

### getMaxHeight

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

```
public int getMaxHeight ()
```

Return the maximum height that the edge effect will be drawn at given the original
`https://developer.android.com/reference/android/widget/EdgeEffect#setSize(int,%20int)`.

<br />

| Returns ||
|---|---|
| `int` | The maximum height of the edge effect <br /> |

### isFinished

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

```
public boolean isFinished ()
```

Reports if this EdgeEffect's animation is finished. If this method returns false
after a call to `https://developer.android.com/reference/android/widget/EdgeEffect#draw(android.graphics.Canvas)` the host widget should schedule another
drawing pass to continue the animation.

<br />

| Returns ||
|---|---|
| `boolean` | true if animation is finished, false if drawing should continue on the next frame. <br /> |

### onAbsorb

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

```
public void onAbsorb (int velocity)
```

Call when the effect absorbs an impact at the given velocity.
Used when a fling reaches the scroll boundary.

When using a `https://developer.android.com/reference/android/widget/Scroller` or `https://developer.android.com/reference/android/widget/OverScroller`,
the method `getCurrVelocity` will provide a reasonable approximation
to use here.

<br />

<br />

| Parameters ||
|---|---|
| `velocity` | `int`: Velocity at impact in pixels per second. <br /> |

### onPull

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

```
public void onPull (float deltaDistance)
```

A view should call this when content is pulled away from an edge by the user.
This will update the state of the current visual effect and its associated animation.
The host view should always `https://developer.android.com/reference/android/view/View#invalidate()` after this
and draw the results accordingly.

Views using EdgeEffect should favor `https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float,%20float)` when the displacement
of the pull point is known.

<br />

<br />

| Parameters ||
|---|---|
| `deltaDistance` | `float`: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect. <br /> |

### onPull

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

```
public void onPull (float deltaDistance, 
                float displacement)
```

A view should call this when content is pulled away from an edge by the user.
This will update the state of the current visual effect and its associated animation.
The host view should always `https://developer.android.com/reference/android/view/View#invalidate()` after this
and draw the results accordingly.

<br />

| Parameters ||
|---|---|
| `deltaDistance` | `float`: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect. <br /> |
| `displacement` | `float`: The displacement from the starting side of the effect of the point initiating the pull. In the case of touch this is the finger position. Values may be from 0-1. <br /> |

### onPullDistance

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

```
public float onPullDistance (float deltaDistance, 
                float displacement)
```

A view should call this when content is pulled away from an edge by the user.
This will update the state of the current visual effect and its associated animation.
The host view should always `https://developer.android.com/reference/android/view/View#invalidate()` after this
and draw the results accordingly. This works similarly to `https://developer.android.com/reference/android/widget/EdgeEffect#onPull(float,%20float)`,
but returns the amount of `deltaDistance` that has been consumed. If the
`https://developer.android.com/reference/android/widget/EdgeEffect#getDistance()` is currently 0 and `deltaDistance` is negative, this
function will return 0 and the drawn value will remain unchanged.

This method can be used to reverse the effect from a pull or absorb and partially consume
some of a motion:

```scdoc
     if (deltaY < 0) {
         float consumed = edgeEffect.onPullDistance(deltaY / getHeight(), x / getWidth());
         deltaY -= consumed * getHeight();
         if (edgeEffect.getDistance() == 0f) edgeEffect.onRelease();
     }
 
```

<br />

<br />

| Parameters ||
|---|---|
| `deltaDistance` | `float`: Change in distance since the last call. Values may be 0 (no change) to 1.f (full length of the view) or negative values to express change back toward the edge reached to initiate the effect. <br /> |
| `displacement` | `float`: The displacement from the starting side of the effect of the point initiating the pull. In the case of touch this is the finger position. Values may be from 0-1. <br /> |

| Returns ||
|---|---|
| `float` | The amount of `deltaDistance` that was consumed, a number between 0 and `deltaDistance`. <br /> |

### onRelease

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

```
public void onRelease ()
```

Call when the object is released after being pulled.
This will begin the "decay" phase of the effect. After calling this method
the host view should `https://developer.android.com/reference/android/view/View#invalidate()` and thereby
draw the results accordingly.

<br />

### setBlendMode

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

```
public void setBlendMode (BlendMode blendmode)
```

Set or clear the blend mode. A blend mode defines how source pixels
(generated by a drawing command) are composited with the destination pixels
(content of the render target).

<br />

Pass null to clear any previous blend mode.

<br />

<br />

<br />

| Parameters ||
|---|---|
| `blendmode` | `BlendMode`: May be null. The blend mode to be installed in the paint <br /> |

**See also:**

- `https://developer.android.com/reference/android/graphics/BlendMode`

### setColor

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

```
public void setColor (int color)
```

Set the color of this edge effect in argb.

<br />

| Parameters ||
|---|---|
| `color` | `int`: Color in argb <br /> |

### setSize

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

```
public void setSize (int width, 
                int height)
```

Set the size of this edge effect in pixels.

<br />

| Parameters ||
|---|---|
| `width` | `int`: Effect width in pixels <br /> |
| `height` | `int`: Effect height in pixels <br /> |