# SplitRule

Artifact: [androidx.window:window](https://developer.android.com/jetpack/androidx/releases/window) [View Source](https://cs.android.com/search?q=file:androidx/window/embedding/SplitRule.kt+class:androidx.window.embedding.SplitRule) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/window#1.0.0)

*** ** * ** ***

<br />

```
open class SplitRule : EmbeddingRule
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.window.embedding.EmbeddingRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingRule) ||
|   | ↳ | [androidx.window.embedding.SplitRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule) |

Known direct subclasses [SplitPairRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPairRule), [SplitPinRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPinRule), [SplitPlaceholderRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPlaceholderRule)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPairRule` | Split configuration rules for activity pairs. |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPinRule` | Split configuration rules for pinning an `https://developer.android.com/reference/kotlin/androidx/window/embedding/ActivityStack`. |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPlaceholderRule` | Configuration rules for split placeholders. |

*** ** * ** ***

Split configuration rules for activities that are launched to side in a split. Define the visual properties of the split. Can be set either via `https://developer.android.com/reference/kotlin/androidx/window/embedding/RuleController#setRules(kotlin.collections.Set)` or via `https://developer.android.com/reference/kotlin/androidx/window/embedding/RuleController#addRule(androidx.window.embedding.EmbeddingRule)`. The rules are always applied only to activities that will be started after the rules were set.

Note that regardless of whether the minimal requirements (`https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minWidthDp()`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minHeightDp()` and `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minSmallestWidthDp()`) are met or not, the callback set in `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)` will still be called for the rule if the calculator is registered via `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1)`. Whether this `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule`'s minimum requirements are satisfied is dispatched in `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributesCalculatorParams#areDefaultConstraintsSatisfied()` instead. The width and height could be verified in the `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes` calculator callback as the sample linked below shows.

It is useful if this `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule` is supported to split the parent container in different directions with different device states.

```kotlin
import androidx.window.embedding.EmbeddingAnimationBackground
import androidx.window.embedding.EmbeddingAnimationParams
import androidx.window.embedding.SplitAttributes
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_EXPAND
import androidx.window.embedding.SplitController

SplitController.getInstance(context).setSplitAttributesCalculator { params ->
    // A sample to split with the dimension that larger than 600 DP. If there's no dimension
    // larger than 600 DP, show the presentation to fill the task bounds.
    val parentConfiguration = params.parentConfiguration
    val builder = SplitAttributes.Builder()
    return@setSplitAttributesCalculator if (parentConfiguration.screenWidthDp >= 600) {
        builder
            .setLayoutDirection(SplitAttributes.LayoutDirection.LOCALE)
            // Optionally set the animation background and change transition animation to use
            // when switching between vertical and horizontal
            .setAnimationParams(
                EmbeddingAnimationParams.Builder()
                    .setAnimationBackground(
                        EmbeddingAnimationBackground.createColorBackground(Color.GRAY)
                    )
                    .setChangeAnimation(EmbeddingAnimationParams.AnimationSpec.JUMP_CUT)
                    .build()
            )
            .build()
    } else if (parentConfiguration.screenHeightDp >= 600) {
        builder
            .setLayoutDirection(SplitAttributes.LayoutDirection.TOP_TO_BOTTOM)
            // Optionally set the animation background and change transition animation to use
            // when switching between vertical and horizontal
            .setAnimationParams(
                EmbeddingAnimationParams.Builder()
                    .setAnimationBackground(
                        EmbeddingAnimationBackground.createColorBackground(Color.GRAY)
                    )
                    .setChangeAnimation(EmbeddingAnimationParams.AnimationSpec.JUMP_CUT)
                    .build()
            )
            .build()
    } else {
        // Fallback to expand the secondary container
        builder.setSplitType(SPLIT_TYPE_EXPAND).build()
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPairRule` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitPlaceholderRule` |   |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule.FinishBehavior` Determines what happens with the associated container when all activities are finished in one of the containers in a split. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW() = 0` When the min dimension is set to this value, it means to always allow split. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT() = 600` The default min dimension in DP for allowing split if it is not set by apps. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT()` The default max aspect ratio for allowing split when the parent window is in landscape. |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT()` The default max aspect ratio for allowing split when the parent window is in portrait. |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#hashCode()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#toString()()` |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#defaultSplitAttributes()` The default `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes` to apply on the activity containers pair when the host task bounds satisfy `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` and `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` requirements. |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#maxAspectRatioInLandscape()` The largest value of the aspect ratio, expressed as `width / height` in decimal form, of the parent window bounds in landscape when the split should be used. |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#maxAspectRatioInPortrait()` The largest value of the aspect ratio, expressed as `height / width` in decimal form, of the parent window bounds in portrait when the split should be used. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minHeightDp()` The smallest value of height of the parent task window when the split should be used, in DP. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minSmallestWidthDp()` The smallest value of the smallest possible width of the parent task window in any rotation when the split should be used, in DP. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minWidthDp()` The smallest value of width of the parent task window when the split should be used, in DP. |

### Inherited properties

From [androidx.window.embedding.EmbeddingRule](https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingRule) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingRule#tag()`

A unique string to identify this `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingRule`, which defaults to `null`.

## Constants

### SPLIT_MIN_DIMENSION_ALWAYS_ALLOW

```
const val SPLIT_MIN_DIMENSION_ALWAYS_ALLOW = 0: Int
```

When the min dimension is set to this value, it means to always allow split.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minWidthDp()` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#minSmallestWidthDp()` |   |

### SPLIT_MIN_DIMENSION_DP_DEFAULT

```
const val SPLIT_MIN_DIMENSION_DP_DEFAULT = 600: Int
```

The default min dimension in DP for allowing split if it is not set by apps. The value reflects `https://developer.android.com/reference/kotlin/androidx/window/core/layout/WindowWidthSizeClass#MEDIUM()`.

## Public companion properties

### SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT

```
val SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT: EmbeddingAspectRatio
```

The default max aspect ratio for allowing split when the parent window is in landscape.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#maxAspectRatioInLandscape()` |   |

### SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT

```
val SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT: EmbeddingAspectRatio
```

The default max aspect ratio for allowing split when the parent window is in portrait.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#maxAspectRatioInPortrait()` |   |

## Public functions

### equals

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

```
open fun hashCode(): Int
```

### toString

```
open fun toString(): String
```

## Public properties

### defaultSplitAttributes

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

```
val defaultSplitAttributes: SplitAttributes
```

The default `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes` to apply on the activity containers pair when the host task bounds satisfy `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)`, `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` and `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#(kotlin.String,kotlin.Int,kotlin.Int,kotlin.Int,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.EmbeddingAspectRatio,androidx.window.embedding.SplitAttributes)` requirements.

It is set to split the host parent task vertically and equally by default.

### maxAspectRatioInLandscape

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

```
val maxAspectRatioInLandscape: EmbeddingAspectRatio
```

The largest value of the aspect ratio, expressed as `width / height` in decimal form, of the parent window bounds in landscape when the split should be used. When the window aspect ratio is greater than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

This value is only used when the parent window is in landscape (width \> height).

The default is `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_LANDSCAPE_DEFAULT()`, which is the recommend value to always allow split when the parent window is in landscape.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ratio(kotlin.Float)` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_ALLOW()` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_DISALLOW()` |   |

### maxAspectRatioInPortrait

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

```
val maxAspectRatioInPortrait: EmbeddingAspectRatio
```

The largest value of the aspect ratio, expressed as `height / width` in decimal form, of the parent window bounds in portrait when the split should be used. When the window aspect ratio is greater than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

This value is only used when the parent window is in portrait (height \>= width).

The default is `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MAX_ASPECT_RATIO_PORTRAIT_DEFAULT()`, which is the recommend value to only allow split when the parent window is not too stretched in portrait.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ratio(kotlin.Float)` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_ALLOW()` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/EmbeddingAspectRatio#ALWAYS_DISALLOW()` |   |

### minHeightDp

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

```
val minHeightDp: @IntRange(from = 0) Int
```

The smallest value of height of the parent task window when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them. It is useful if it's necessary to split the parent window horizontally for this `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule`.

The default is `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.LayoutDirection#TOP_TO_BOTTOM()` |   |
| `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.LayoutDirection#BOTTOM_TO_TOP()` |   |

### minSmallestWidthDp

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

```
val minSmallestWidthDp: @IntRange(from = 0) Int
```

The smallest value of the smallest possible width of the parent task window in any rotation when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

The default is `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.

### minWidthDp

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

```
val minWidthDp: @IntRange(from = 0) Int
```

The smallest value of width of the parent task window when the split should be used, in DP. When the window size is smaller than requested here, activities in the secondary container will be stacked on top of the activities in the primary one, completely overlapping them.

The default is `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_DP_DEFAULT()` if the app doesn't set. `https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitRule#SPLIT_MIN_DIMENSION_ALWAYS_ALLOW()` means to always allow split.