# MultiSlotLayout

# MultiSlotLayout

Artifact:[androidx.wear.protolayout:protolayout-material](https://developer.android.com/jetpack/androidx/releases/wear-protolayout)  
[View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/material/layouts/MultiSlotLayout.java+class:androidx.wear.protolayout.material.layouts.MultiSlotLayout)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiSlotLayout "View this page in Java")

<br />

```
class MultiSlotLayout : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

Opinionated ProtoLayout layout, row like style with horizontally aligned and spaced slots (for icons or other small content). Should be used as a content passed in to the[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout). Visuals and design samples can be found[here](https://developer.android.com/design/ui/wear/guides/surfaces/tiles-layouts#info-centric-with-progress-indicator).

Recommended number of added slots is 1 to 3. Their width will be the width of an element passed in, with the[MULTI_SLOT_LAYOUT_HORIZONTAL_SPACER_WIDTH](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/LayoutDefaults#MULTI_SLOT_LAYOUT_HORIZONTAL_SPACER_WIDTH())space between.

When accessing the contents of a container for testing, note that this element can't be simply casted back to the original type, i.e.:  

```kotlin
MultiSlotLayout msl = new MultiSlotLayout...
Box box = new Box.Builder().addContent(msl).build();

MultiSlotLayout myMsl = (MultiSlotLayout) box.getContents().get(0);
```
will fail.

To be able to get[MultiSlotLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout)object from any layout element,[fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))method should be used, i.e.:  

```kotlin
MultiSlotLayout myMsl = MultiSlotLayout.fromLayoutElement(box.getContents().get(0));
```

## Summary

|                                                                                                                                          ### Nested types                                                                                                                                           |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[MultiSlotLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout.Builder) Builder class for[MultiSlotLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout). |

|                                                                                                                                                                     ### Public functions                                                                                                                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[MultiSlotLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout)`?`                                                                                                                                                                                                                 | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Returns MultiSlotLayout object from the given LayoutElement (e.g. one retrieved from a container's content with`container.getContents().get(index)`) if that element can be converted to MultiSlotLayout. |
| `@`[Dimension](https://developer.android.com/reference/kotlin/androidx/annotation/Dimension)`(unit = 0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                                                                                                                                      | [getHorizontalSpacerWidth](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout#getHorizontalSpacerWidth())`()` Gets the width of horizontal spacer that is between slots.                                                                                                                                                                                                                                                                                                                                                             |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`!>` | [getSlotContents](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiSlotLayout#getSlotContents())`()` Gets the content from this layout, containing all slots that were added.                                                                                                                                                                                                                                                                                                                                                                 |

## Public functions

### fromLayoutElement

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

```
java-static fun fromLayoutElement(element: LayoutElementBuilders.LayoutElement): MultiSlotLayout?
```

Returns MultiSlotLayout object from the given LayoutElement (e.g. one retrieved from a container's content with`container.getContents().get(index)`) if that element can be converted to MultiSlotLayout. Otherwise, it will return null.  

### getHorizontalSpacerWidth

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

```
fun getHorizontalSpacerWidth(): @Dimension(unit = 0) Float
```

Gets the width of horizontal spacer that is between slots.  

### getSlotContents

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

```
fun getSlotContents(): (Mutable)List<LayoutElementBuilders.LayoutElement!>
```

Gets the content from this layout, containing all slots that were added.