# ColorBuilders.LinearGradient.Builder

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/ColorBuilders.java+class:androidx.wear.protolayout.ColorBuilders.LinearGradient.Builder) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

*** ** * ** ***


```
public final class ColorBuilders.LinearGradient.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient`.

## Summary

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) @https://developer.android.com/reference/java/lang/SafeVarargs.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#Builder(androidx.wear.protolayout.ColorBuilders.ColorStop...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ColorBuilders.ColorStop[] colorStops)` Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder`. |
| `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) @https://developer.android.com/reference/java/lang/SafeVarargs.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#Builder(androidx.wear.protolayout.ColorBuilders.ColorProp...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ColorBuilders.ColorProp[] colors)` Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient` | `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#build()()` Builds an instance from accumulated values. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#setEndX(androidx.wear.protolayout.DimensionBuilders.OffsetDimension)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.OffsetDimension endX)` Sets the ending y position of the linear gradient. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#setEndY(androidx.wear.protolayout.DimensionBuilders.OffsetDimension)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.OffsetDimension endY)` Sets the ending y position of the linear gradient. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#setStartX(androidx.wear.protolayout.DimensionBuilders.OffsetDimension)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.OffsetDimension startX)` Sets the starting x position of the linear gradient. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 500) https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#setStartY(androidx.wear.protolayout.DimensionBuilders.OffsetDimension)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.OffsetDimension startY)` Sets the starting y position of the linear gradient. |

## Public constructors

### Builder

```
@RequiresSchemaVersion(major = 1, minor = 500)
@SafeVarargs
public Builder(@NonNull ColorBuilders.ColorStop[] colorStops)
```

Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ColorBuilders.ColorStop[] colorStops` | The color stops defining how the colors are distributed from the start to the end coordinates. A color stop is a pair of a color and its offset in the gradient. The offset is the relative position of the color, beginning with 0 from the start coordinate and ending with 1.0 at the end coordinate. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the number of colors is less than 2 or larger than 10. |

### Builder

```
@RequiresSchemaVersion(major = 1, minor = 500)
@SafeVarargs
public Builder(@NonNull ColorBuilders.ColorProp[] colors)
```

Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder`.

The colors are evenly distributed in the gradient.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ColorBuilders.ColorProp[] colors` | The color sequence to be distributed between the gradient's start and end coordinates. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the number of colors is less than 2 or larger than 10. |

## Public methods

### build

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
public @NonNull ColorBuilders.LinearGradient build()
```

Builds an instance from accumulated values.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if size of colorStops is less than 2 or greater than 10. |

### setEndX

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
@RequiresSchemaVersion(major = 1, minor = 500)
public @NonNull ColorBuilders.LinearGradient.Builder setEndX(@NonNull DimensionBuilders.OffsetDimension endX)
```

Sets the ending y position of the linear gradient. Defaults to the right side of the element.

### setEndY

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
@RequiresSchemaVersion(major = 1, minor = 500)
public @NonNull ColorBuilders.LinearGradient.Builder setEndY(@NonNull DimensionBuilders.OffsetDimension endY)
```

Sets the ending y position of the linear gradient. Defaults to the top side of the element.

### setStartX

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
@RequiresSchemaVersion(major = 1, minor = 500)
public @NonNull ColorBuilders.LinearGradient.Builder setStartX(@NonNull DimensionBuilders.OffsetDimension startX)
```

Sets the starting x position of the linear gradient. Defaults to the left side of the element.

### setStartY

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

```
@RequiresSchemaVersion(major = 1, minor = 500)
public @NonNull ColorBuilders.LinearGradient.Builder setStartY(@NonNull DimensionBuilders.OffsetDimension startY)
```

Sets the starting y position of the linear gradient. Defaults to the top side of the element.