# Parallax

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/Parallax.java+class:androidx.leanback.widget.Parallax) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***


```
abstract class Parallax<PropertyT : Property?>
```

<br />

Known direct subclasses [RecyclerViewParallax](https://developer.android.com/reference/kotlin/androidx/leanback/widget/RecyclerViewParallax)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/RecyclerViewParallax` | Implementation of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax` class for `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView`. |

Known indirect subclasses [DetailsParallax](https://developer.android.com/reference/kotlin/androidx/leanback/widget/DetailsParallax)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/DetailsParallax` | Subclass of Parallax object that tracks overview row's top and bottom edge in DetailsFragment or DetailsSupportFragment. |

*** ** * ** ***

Parallax tracks a list of dynamic `https://developer.android.com/reference/android/util/Property.html`s typically representing foreground UI element positions on screen. Parallax keeps a list of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` objects which define rules to mapping property values to `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxTarget`.

Example: `
// when Property "var1" changes from 15 to max value, perform parallax effect to
// change myView's translationY from 0 to 100.
Parallaxparallax = new Parallax`

To create a `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect`, user calls `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#addEffect(androidx.leanback.widget.Parallax.PropertyMarkerValue...)` with a list of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.PropertyMarkerValue` which defines the range of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.IntProperty` or `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.FloatProperty`. Then user adds `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxTarget` into `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect`.

App may subclass `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.IntProperty` or `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.FloatProperty` to supply additional information about how to retrieve Property value. `https://developer.android.com/reference/kotlin/androidx/leanback/widget/RecyclerViewParallax` is a great example of Parallax implementation tracking child view positions on screen.

Restrictions of properties

- FloatProperty and IntProperty cannot be mixed in one Parallax
- Values must be in ascending order.
- If the UI element is unknown above screen, use UNKNOWN_BEFORE.
- if the UI element is unknown below screen, use UNKNOWN_AFTER.
- UNKNOWN_BEFORE and UNKNOWN_AFTER are not allowed to be next to each other.

These rules will be verified at runtime.

Subclass must override `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()` to update property values and perform `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect`s. Subclass may call `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()` automatically e.g. `https://developer.android.com/reference/kotlin/androidx/leanback/widget/RecyclerViewParallax` calls `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()` in RecyclerView scrolling. App might call `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()` manually when Parallax is unaware of the value change. For example, when a slide transition is running, `https://developer.android.com/reference/kotlin/androidx/leanback/widget/RecyclerViewParallax` is unaware of translation value changes; it's the app's responsibility to call `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()` in every frame of animation.

| Parameters |
|---|---|
| `<PropertyT : https://developer.android.com/reference/android/util/Property.html?>` | Subclass of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.IntProperty` or `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.FloatProperty` |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.FloatProperty : https://developer.android.com/reference/android/util/Property.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html!>` FloatProperty provide access to an index based integer type property inside `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax`. |
| `class https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.IntProperty : https://developer.android.com/reference/android/util/Property.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!>` IntProperty provide access to an index based integer type property inside `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax`. |
| `class https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.PropertyMarkerValue<PropertyT>` Class holding a fixed value for a Property in `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#Parallax()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#addEffect(androidx.leanback.widget.Parallax.PropertyMarkerValue...)(ranges: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.PropertyMarkerValue!>!)` Create a `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object that will track source variable changes within a provided set of ranges. |
| `PropertyT!` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#addProperty(java.lang.String)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Add a new IntProperty in the Parallax object. |
| `abstract PropertyT!` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#createProperty(java.lang.String,int)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Create a new Property object. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!>!` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#getEffects()()` Returns a list of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object which defines rules to perform mapping to multiple `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxTarget`s. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#getMaxValue()()` Return the max value which is typically size of parent visible area, e.g. RecyclerView's height if we are tracking Y position of a child. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<PropertyT!>!` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#getProperties()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#removeAllEffects()()` Remove all `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` objects. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#removeEffect(androidx.leanback.widget.ParallaxEffect)(effect: https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!)` Remove the `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#updateValues()()` Update property values and perform `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect`s. |

## Public constructors

### Parallax

Added in 1.1.0

```
Parallax()
```

## Public functions

### addEffect

```
fun addEffect(ranges: Array<Parallax.PropertyMarkerValue!>!): ParallaxEffect!
```

Create a `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object that will track source variable changes within a provided set of ranges.

| Parameters |
|---|---|
| `ranges: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax.PropertyMarkerValue!>!` | A list of marker values that defines the ranges. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!` | Newly created ParallaxEffect object. |

### addProperty

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
fun addProperty(name: String!): PropertyT!
```

Add a new IntProperty in the Parallax object. App may override `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#createProperty(java.lang.String,int)`.

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Name of the property. |

| Returns |
|---|---|
| `PropertyT!` | Newly created Property object. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#createProperty(java.lang.String,int)` |   |

### createProperty

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
abstract fun createProperty(name: String!, index: Int): PropertyT!
```

Create a new Property object. App does not directly call this method. See `https://developer.android.com/reference/kotlin/androidx/leanback/widget/Parallax#addProperty(java.lang.String)`.

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Name of the property in this Parallax object |
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Index of the property in this Parallax object. |

| Returns |
|---|---|
| `PropertyT!` | Newly created Property object. |

### getEffects

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
fun getEffects(): (Mutable)List<ParallaxEffect!>!
```

Returns a list of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object which defines rules to perform mapping to multiple `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxTarget`s.

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!>!` | A list of `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object. |

### getMaxValue

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
abstract fun getMaxValue(): Float
```

Return the max value which is typically size of parent visible area, e.g. RecyclerView's height if we are tracking Y position of a child. The size can be used to calculate marker value using the provided fraction of FloatPropertyMarkerValue.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | Size of parent visible area. |

### getProperties

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
fun getProperties(): (Mutable)List<PropertyT!>!
```

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<PropertyT!>!` | A unmodifiable list of properties. |

### removeAllEffects

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
fun removeAllEffects(): Unit
```

Remove all `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` objects.

### removeEffect

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
fun removeEffect(effect: ParallaxEffect!): Unit
```

Remove the `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object.

| Parameters |
|---|---|
| `effect: https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect!` | The `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect` object to remove. |

### updateValues

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
@CallSuper
fun updateValues(): Unit
```

Update property values and perform `https://developer.android.com/reference/kotlin/androidx/leanback/widget/ParallaxEffect`s. Subclass may override and call super.updateValues() after updated properties values.