# ColorBuilders.LinearGradient.Builder

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder "View this page in Java")

<br />

```
class ColorBuilders.LinearGradient.Builder
```

<br />

*** ** * ** ***

Builder for[LinearGradient](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                   ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                                    |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[RequiresSchemaVersion](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion)`(major = 1, minor = 500)` `@`[SafeVarargs](https://developer.android.com/reference/java/lang/SafeVarargs.html) [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#Builder(androidx.wear.protolayout.ColorBuilders.ColorStop...))`(colorStops: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ColorBuilders.ColorStop](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorStop)`!>)` Creates an instance of[Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder). |
| `@`[RequiresSchemaVersion](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/expression/RequiresSchemaVersion)`(major = 1, minor = 500)` `@`[SafeVarargs](https://developer.android.com/reference/java/lang/SafeVarargs.html) [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder#Builder(androidx.wear.protolayout.ColorBuilders.ColorProp...))`(colors: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ColorBuilders.ColorProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorProp)`!>)` Creates an instance of[Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder).     |

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

## Public constructors

### Builder

```
@RequiresSchemaVersion(major = 1, minor = 500)
@SafeVarargs
Builder(colorStops: Array<ColorBuilders.ColorStop!>)
```

Creates an instance of[Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder).  

|                                                                                                           Parameters                                                                                                            |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `colorStops: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ColorBuilders.ColorStop](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorStop)`!>` | 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                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| [java.lang.IllegalArgumentException](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
Builder(colors: Array<ColorBuilders.ColorProp!>)
```

Creates an instance of[Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.LinearGradient.Builder).

The colors are evenly distributed in the gradient.  

|                                                                                                         Parameters                                                                                                          |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| `colors: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ColorBuilders.ColorProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ColorBuilders.ColorProp)`!>` | The color sequence to be distributed between the gradient's start and end coordinates. |

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

## Public functions

### build

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

```
fun build(): ColorBuilders.LinearGradient
```

Builds an instance from accumulated values.  

|                                                     Throws                                                      |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [java.lang.IllegalStateException](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)
fun setEndX(endX: DimensionBuilders.OffsetDimension): ColorBuilders.LinearGradient.Builder
```

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)
fun setEndY(endY: DimensionBuilders.OffsetDimension): ColorBuilders.LinearGradient.Builder
```

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)
fun setStartX(startX: DimensionBuilders.OffsetDimension): ColorBuilders.LinearGradient.Builder
```

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)
fun setStartY(startY: DimensionBuilders.OffsetDimension): ColorBuilders.LinearGradient.Builder
```

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