# SplitAttributes.SplitType

# SplitAttributes.SplitType

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/window/embedding/SplitAttributes.SplitType "View this page in Java")

<br />

```
class SplitAttributes.SplitType
```

<br />

*** ** * ** ***

The type of parent window split, which defines the proportion of the parent window occupied by the primary and secondary activity containers.

## Summary

|                                                 ### Public companion functions                                                  |
|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SplitAttributes.SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType) | [ratio](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#ratio(kotlin.Float))`(` ` ratio: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) `)` Creates a split type based on the proportion of the parent window occupied by the primary container of the split. |

|                                                 ### Public companion properties                                                 |
|---------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SplitAttributes.SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType) | [SPLIT_TYPE_EQUAL](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EQUAL()) A split type in which the primary and secondary containers occupy equal portions of the parent window.                                                               |
| [SplitAttributes.SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType) | [SPLIT_TYPE_EXPAND](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EXPAND()) A split type in which the primary and secondary activity containers each expand to fill the parent window; the secondary container overlays the primary container. |
| [SplitAttributes.SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType) | [SPLIT_TYPE_HINGE](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_HINGE()) A split type in which the split ratio conforms to the position of a hinge or separating fold in the device display.                                                  |

|                                        ### Public functions                                         |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `open operator `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [equals](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#equals(kotlin.Any))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)` Determines whether this object is the same type of split as the compared object. |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                  | [hashCode](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#hashCode())`()` Returns a hash code for this split type.                                                                                                                                    |
| `open `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)            | [toString](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#toString())`()` A string representation of this split type.                                                                                                                                 |

## Public companion functions

### ratio

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

```
fun ratio(
    ratio: @FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) Float
): SplitAttributes.SplitType
```

Creates a split type based on the proportion of the parent window occupied by the primary container of the split.

Values in the non-inclusive range (0.0, 1.0) define the size of the primary container relative to the size of the parent window:

- 0.5 --- Primary container occupies half of the parent window; secondary container, the other half

- \> 0.5 --- Primary container occupies a larger proportion of the parent window than the secondary container

- \< 0.5 --- Primary container occupies a smaller proportion of the parent window than the secondary container

|                                                                                                                        Parameters                                                                                                                         |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| `ratio: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The proportion of the parent window occupied by the primary container of the split. |

|                                                             Returns                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| [SplitAttributes.SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType) | An instance of`SplitType`with the specified ratio. |

## Public companion properties

### SPLIT_TYPE_EQUAL

```
val SPLIT_TYPE_EQUAL: SplitAttributes.SplitType
```

A split type in which the primary and secondary containers occupy equal portions of the parent window.

Serves as the default[SplitType](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType).  

### SPLIT_TYPE_EXPAND

```
val SPLIT_TYPE_EXPAND: SplitAttributes.SplitType
```

A split type in which the primary and secondary activity containers each expand to fill the parent window; the secondary container overlays the primary container.

It is useful to use this`SplitType`with the function set in[SplitController.setSplitAttributesCalculator](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1))to expand the activity containers in some device or window states. The following sample shows how to always fill the parent bounds if the device is in portrait orientation:  

```kotlin
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 always fill task bounds when the device is in portrait.
    val tag = params.splitRuleTag
    val bounds = params.parentWindowMetrics.bounds
    val defaultSplitAttributes = params.defaultSplitAttributes
    val areDefaultConstraintsSatisfied = params.areDefaultConstraintsSatisfied

    val expandContainersAttrs =
        SplitAttributes.Builder().setSplitType(SPLIT_TYPE_EXPAND).build()
    if (!areDefaultConstraintsSatisfied) {
        return@setSplitAttributesCalculator expandContainersAttrs
    }
    // Always expand containers for the splitRule tagged as
    // TAG_SPLIT_RULE_EXPAND_IN_PORTRAIT if the device is in portrait
    // even if [areDefaultConstraintsSatisfied] reports true.
    if (bounds.height() > bounds.width() && TAG_SPLIT_RULE_EXPAND_IN_PORTRAIT == tag) {
        return@setSplitAttributesCalculator expandContainersAttrs
    }
    // Otherwise, use the default splitAttributes.
    return@setSplitAttributesCalculator defaultSplitAttributes
}
```  

### SPLIT_TYPE_HINGE

```
val SPLIT_TYPE_HINGE: SplitAttributes.SplitType
```

A split type in which the split ratio conforms to the position of a hinge or separating fold in the device display.

The split type works only if:

- The host task is not in multi-window mode (e.g., split-screen mode or picture-in-picture mode)
- The device has a hinge or separating fold reported by \[androidx.window.layout.FoldingFeature.isSeparating\]
- The hinge or separating fold orientation matches how the parent bounds are split:
  - The hinge or fold orientation is vertical, and the parent bounds are also split vertically (containers are side by side)
  - The hinge or fold orientation is horizontal, and the parent bounds are also split horizontally (containers are top and bottom)

Otherwise, this`SplitType`fallback to show the split with[SPLIT_TYPE_EQUAL](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EQUAL()).

If the app wants to have another fallback`SplitType`if[SPLIT_TYPE_HINGE](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_HINGE())cannot be applied. It is suggested to use[SplitController.setSplitAttributesCalculator](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitController#setSplitAttributesCalculator(kotlin.Function1))to customize the fallback`SplitType`.

The following sample shows how to fallback to[SPLIT_TYPE_EXPAND](https://developer.android.com/reference/kotlin/androidx/window/embedding/SplitAttributes.SplitType#SPLIT_TYPE_EXPAND())if there's no hinge area in the parent window container bounds.  

```kotlin
import androidx.window.embedding.SplitAttributes
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_EXPAND
import androidx.window.embedding.SplitAttributes.SplitType.Companion.SPLIT_TYPE_HINGE
import androidx.window.embedding.SplitController
import androidx.window.layout.FoldingFeature

SplitController.getInstance(context).setSplitAttributesCalculator { params ->
    SplitAttributes.Builder()
        .setSplitType(
            if (
                params.parentWindowLayoutInfo.displayFeatures
                    .filterIsInstance<FoldingFeature>()
                    .isNotEmpty()
            ) {
                SPLIT_TYPE_HINGE
            } else {
                SPLIT_TYPE_EXPAND
            }
        )
        .build()
}
```  

## Public functions

### equals

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

Determines whether this object is the same type of split as the compared object.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------------------|
| `other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?` | The object to compare to this object. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the objects are the same split type, false otherwise. |

### hashCode

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

Returns a hash code for this split type.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|--------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The hash code for this object. |

### toString

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

A string representation of this split type.  

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The string representation of the object. |