Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/graphics/LinearGradient#pubctors) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/LinearGradient#inhmethods)

# LinearGradient

*** ** * ** ***

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


`
public


class
LinearGradient
`


`


`

`

extends https://developer.android.com/reference/android/graphics/Shader


`

`


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.graphics.Shader](https://developer.android.com/reference/android/graphics/Shader) ||
|   | ↳ | android.graphics.LinearGradient |

<br />

*** ** * ** ***

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/LinearGradient#LinearGradient(float,%20float,%20float,%20float,%20int,%20int,%20android.graphics.Shader.TileMode)(float x0, float y0, float x1, float y1, int color0, int color1, https://developer.android.com/reference/android/graphics/Shader.TileMode tile) ` Create a shader that draws a linear gradient along a line. |
| ` https://developer.android.com/reference/android/graphics/LinearGradient#LinearGradient(float,%20float,%20float,%20float,%20int[],%20float[],%20android.graphics.Shader.TileMode)(float x0, float y0, float x1, float y1, int[] colors, float[] positions, https://developer.android.com/reference/android/graphics/Shader.TileMode tile) ` Create a shader that draws a linear gradient along a line. |
| ` https://developer.android.com/reference/android/graphics/LinearGradient#LinearGradient(float,%20float,%20float,%20float,%20long,%20long,%20android.graphics.Shader.TileMode)(float x0, float y0, float x1, float y1, long color0, long color1, https://developer.android.com/reference/android/graphics/Shader.TileMode tile) ` Create a shader that draws a linear gradient along a line. |
| ` https://developer.android.com/reference/android/graphics/LinearGradient#LinearGradient(float,%20float,%20float,%20float,%20long[],%20float[],%20android.graphics.Shader.TileMode)(float x0, float y0, float x1, float y1, long[] colors, float[] positions, https://developer.android.com/reference/android/graphics/Shader.TileMode tile) ` Create a shader that draws a linear gradient along a line. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/android/graphics/Shader ` |---|---| | ` boolean` | ` https://developer.android.com/reference/android/graphics/Shader#getLocalMatrix(android.graphics.Matrix)(https://developer.android.com/reference/android/graphics/Matrix localM) ` Return true if the shader has a non-identity local matrix. | | ` void` | ` https://developer.android.com/reference/android/graphics/Shader#setLocalMatrix(android.graphics.Matrix)(https://developer.android.com/reference/android/graphics/Matrix localM) ` Set the shader's local matrix. | ||
| 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

### LinearGradient

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

```
public LinearGradient (float x0, 
                float y0, 
                float x1, 
                float y1, 
                int color0, 
                int color1, 
                Shader.TileMode tile)
```

Create a shader that draws a linear gradient along a line.

<br />

| Parameters ||
|---|---|
| `x0` | `float`: The x-coordinate for the start of the gradient line <br /> |
| `y0` | `float`: The y-coordinate for the start of the gradient line <br /> |
| `x1` | `float`: The x-coordinate for the end of the gradient line <br /> |
| `y1` | `float`: The y-coordinate for the end of the gradient line <br /> |
| `color0` | `int`: The sRGB color at the start of the gradient line. <br /> |
| `color1` | `int`: The sRGB color at the end of the gradient line. <br /> |
| `tile` | `Shader.TileMode`: The Shader tiling mode. This value cannot be `null`. <br /> |

### LinearGradient

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

```
public LinearGradient (float x0, 
                float y0, 
                float x1, 
                float y1, 
                int[] colors, 
                float[] positions, 
                Shader.TileMode tile)
```

Create a shader that draws a linear gradient along a line.

<br />

| Parameters ||
|---|---|
| `x0` | `float`: The x-coordinate for the start of the gradient line <br /> |
| `y0` | `float`: The y-coordinate for the start of the gradient line <br /> |
| `x1` | `float`: The x-coordinate for the end of the gradient line <br /> |
| `y1` | `float`: The y-coordinate for the end of the gradient line <br /> |
| `colors` | `int`: The sRGB colors to be distributed along the gradient line. This value cannot be `null`. <br /> |
| `positions` | `float`: May be null. The relative positions \[0..1\] of each corresponding color in the colors array. If this is null, the colors are distributed evenly along the gradient line. <br /> |
| `tile` | `Shader.TileMode`: The Shader tiling mode. This value cannot be `null`. <br /> |

### LinearGradient

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

```
public LinearGradient (float x0, 
                float y0, 
                float x1, 
                float y1, 
                long color0, 
                long color1, 
                Shader.TileMode tile)
```

Create a shader that draws a linear gradient along a line.

<br />

| Parameters ||
|---|---|
| `x0` | `float`: The x-coordinate for the start of the gradient line <br /> |
| `y0` | `float`: The y-coordinate for the start of the gradient line <br /> |
| `x1` | `float`: The x-coordinate for the end of the gradient line <br /> |
| `y1` | `float`: The y-coordinate for the end of the gradient line <br /> |
| `color0` | `long`: The color at the start of the gradient line. <br /> |
| `color1` | `long`: The color at the end of the gradient line. <br /> |
| `tile` | `Shader.TileMode`: The Shader tiling mode. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the colors do not share the same `https://developer.android.com/reference/android/graphics/ColorSpace` or do not use a valid one. |

### LinearGradient

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

```
public LinearGradient (float x0, 
                float y0, 
                float x1, 
                float y1, 
                long[] colors, 
                float[] positions, 
                Shader.TileMode tile)
```

Create a shader that draws a linear gradient along a line.

<br />

| Parameters ||
|---|---|
| `x0` | `float`: The x-coordinate for the start of the gradient line <br /> |
| `y0` | `float`: The y-coordinate for the start of the gradient line <br /> |
| `x1` | `float`: The x-coordinate for the end of the gradient line <br /> |
| `y1` | `float`: The y-coordinate for the end of the gradient line <br /> |
| `colors` | `long`: The colors to be distributed along the gradient line. This value cannot be `null`. <br /> |
| `positions` | `float`: May be null. The relative positions \[0..1\] of each corresponding color in the colors array. If this is null, the colors are distributed evenly along the gradient line. <br /> |
| `tile` | `Shader.TileMode`: The Shader tiling mode. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if there are less than two colors, the colors do not share the same `https://developer.android.com/reference/android/graphics/ColorSpace` or do not use a valid one, or `positions` is not `null` and has a different length from `colors`. |