AutoCenteringParams

Class

Android
public class AutoCenteringParams(
    internal val itemIndex: Int = 1,
    internal val itemOffset: Int = 0,
)

Parameters to determine which list item and offset to calculate auto-centering spacing for. The default values are itemIndex = 1 and itemOffset = 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 itemIndex = 0.

The higher the value for 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 setting 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.

itemOffset allows adjustment of the items position relative the ScalingLazyColumns 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 rememberScalingLazyListState 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.

For an example of a ScalingLazyColumn with an explicit itemOffset see:

Parameters

itemIndexWhich list item index to enable auto-centering from. Space (padding) will be added such that items with index 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.
itemOffsetWhat offset, if any, to apply when calculating space for auto-centering the itemIndex item. E.g. itemOffset can be used if the developer wants to align the viewport center in the gap between two list items.