# AutoCenteringParams

Artifact: [androidx.wear.compose:compose-material](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/material/ScalingLazyColumn.kt+class:androidx.wear.compose.material.AutoCenteringParams) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.2.0)

<br />

```
class AutoCenteringParams
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
> Was moved to androidx.wear.compose.foundation.lazy package. Please use it instead

Parameters to determine which list item and offset to calculate auto-centering spacing for. The default values are `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` = 1 and `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#(kotlin.Int,kotlin.Int)` = 0. This will provide sufficient padding for the second item (index = 1) in the list being centerable. This is to match the Wear UX guidelines that a typical list will have a ListHeader item as the first item in the list (index = 0) and that this should not be scrollable into the middle of the viewport, instead the first list item that a user can interact with (index = 1) would be the first that would be in the center.

If your use case is different and you want all list items to be able to be scrolled to the viewport middle, including the first item in the list then set `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` = 0.

The higher the value for `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` you provide the less auto centering padding will be provided as the amount of padding needed to allow that item to be centered will reduce. Even for a list of short items (such as `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/CompactChip.composable#CompactChip(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Function1,kotlin.Function1,androidx.wear.compose.material.ChipColors,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.layout.PaddingValues,androidx.compose.ui.graphics.Shape,androidx.wear.compose.material.ChipBorder)`) setting `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` above 3 or 4 is likely to result in no auto-centering padding being provided as items with index 3 or 4 will probably already be naturally scrollable to the center of the viewport.

`https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#(kotlin.Int,kotlin.Int)` allows adjustment of the items position relative the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ScalingLazyColumn.composable#ScalingLazyColumn(androidx.compose.ui.Modifier,androidx.wear.compose.material.ScalingLazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.wear.compose.material.ScalingParams,androidx.wear.compose.material.ScalingLazyListAnchorType,androidx.wear.compose.material.AutoCenteringParams,kotlin.Function1)`s `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ScalingLazyListAnchorType`. This can be useful if you need fine grained control over item positioning and spacing, e.g. If you are lining up the gaps between two items on the viewport center line where you would want to set the offset to half the distance between listItems in pixels.

See also `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/rememberScalingLazyListState.composable#rememberScalingLazyListState(kotlin.Int,kotlin.Int)` where similar fields are provided to allow control over the initially selected centered item index and offset. By default these match the auto centering defaults meaning that the second item (index = 1) will be the item scrolled to the viewport center.

```kotlin
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.wear.compose.foundation.lazy.AutoCenteringParams
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyListAnchorType
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.Chip
import androidx.wear.compose.material.ChipDefaults
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.material.Text

val coroutineScope = rememberCoroutineScope()
val itemSpacing = 6.dp
// Line up the gap between the items on the center-line
val scrollOffset = with(LocalDensity.current) { -(itemSpacing / 2).roundToPx() }
val state =
    rememberScalingLazyListState(
        initialCenterItemIndex = 1,
        initialCenterItemScrollOffset = scrollOffset,
    )

ScalingLazyColumn(
    modifier = Modifier.fillMaxWidth(),
    anchorType = ScalingLazyListAnchorType.ItemStart,
    verticalArrangement = Arrangement.spacedBy(itemSpacing),
    state = state,
    autoCentering = AutoCenteringParams(itemOffset = scrollOffset),
) {
    item { ListHeader { Text(text = "List Header") } }
    items(20) {
        Chip(
            onClick = {
                coroutineScope.launch {
                    // Add +1 to allow for the ListHeader
                    state.animateScrollToItem(it + 1, scrollOffset)
                }
            },
            label = { Text("List item $it") },
            colors = ChipDefaults.secondaryChipColors(),
        )
    }
}
```

## Summary

| ### Public constructors |
|---|
| `[AutoCenteringParams](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#AutoCenteringParams(kotlin.Int,kotlin.Int))(itemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Was moved to androidx.wear.compose.foundation.lazy package. |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[equals](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#equals(kotlin.Any))(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` **This function is deprecated.** Was moved to androidx.wear.compose.foundation.lazy package. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[hashCode](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#hashCode())()` **This function is deprecated.** Was moved to androidx.wear.compose.foundation.lazy package. |

## Public constructors

### AutoCenteringParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.2.0)

```
[AutoCenteringParams](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#AutoCenteringParams(kotlin.Int,kotlin.Int))(itemIndex: Int = 1, itemOffset: Int = 0)
```

> [!CAUTION]
> **This function is deprecated.**   
> Was moved to androidx.wear.compose.foundation.lazy package. Please use it instead

| Parameters |
|---|---|
| `itemIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 1` | Which list item index to enable auto-centering from. Space (padding) will be added such that items with index `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` or greater will be able to be scrolled to the center of the viewport. If the developer wants to add additional space to allow other list items to also be scrollable to the center they can use contentPadding on the ScalingLazyColumn. If the developer wants custom control over position and spacing they can switch off autoCentering and provide contentPadding. |
| `itemOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | What offset, if any, to apply when calculating space for auto-centering the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#itemIndex()` item. E.g. itemOffset can be used if the developer wants to align the viewport center in the gap between two list items. For an example of a `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ScalingLazyColumn.composable#ScalingLazyColumn(androidx.compose.ui.Modifier,androidx.wear.compose.material.ScalingLazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.wear.compose.material.ScalingParams,androidx.wear.compose.material.ScalingLazyListAnchorType,androidx.wear.compose.material.AutoCenteringParams,kotlin.Function1)` with an explicit itemOffset see: |

## Public functions

### equals

```
open operator fun [equals](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#equals(kotlin.Any))(other: Any?): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
> Was moved to androidx.wear.compose.foundation.lazy package. Please use it instead

### hashCode

```
open fun [hashCode](https://developer.android.com/reference/kotlin/androidx/wear/compose/material/AutoCenteringParams#hashCode())(): Int
```

> [!CAUTION]
> **This function is deprecated.**   
> Was moved to androidx.wear.compose.foundation.lazy package. Please use it instead