# MultiButtonLayout

# MultiButtonLayout

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/MultiButtonLayout.java+class:androidx.wear.protolayout.material.layouts.MultiButtonLayout)  
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/MultiButtonLayout "View this page in Java")

<br />

```
class MultiButtonLayout : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

Opinionated ProtoLayout layout, that can contain between 1 and[MAX_BUTTONS](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/LayoutDefaults.MultiButtonLayoutDefaults#MAX_BUTTONS())number of buttons arranged inline with the Material guidelines. Can be used as a content passed in to the[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout), but if there is[MAX_BUTTONS](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/LayoutDefaults.MultiButtonLayoutDefaults#MAX_BUTTONS())buttons it should be used on its own. Visuals and design samples can be found \*[here](https://developer.android.com/design/ui/wear/guides/surfaces/tiles-layouts#button-centric-buttons).

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
MultiButtonLayout mbl = new MultiButtonLayout...
Box box = new Box.Builder().addContent(mbl).build();

MultiButtonLayout myMbl = (MultiButtonLayout) box.getContents().get(0);
```
will fail.

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

```kotlin
MultiButtonLayout myMbl = MultiButtonLayout.fromLayoutElement(box.getContents().get(0));
```

## Summary

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

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY())` = 2` Button distribution where the last row has more buttons than other rows. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [FIVE_BUTTON_DISTRIBUTION_TOP_HEAVY](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#FIVE_BUTTON_DISTRIBUTION_TOP_HEAVY())` = 1` Button distribution where the first row has more buttons than other rows.      |

|                                                                                                                                                                     ### Public functions                                                                                                                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[MultiButtonLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout)`?`                                                                                                                                                                                                             | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Returns MultiButtonLayout 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 MultiButtonLayout. |
| `(`[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)`!>` | [getButtonContents](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#getButtonContents())`()` Gets the content from this layout, containing all buttons that were added.                                                                                                                                                                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                                                                                                                   | [getFiveButtonDistribution](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#getFiveButtonDistribution())`()` Gets the button distribution from this layout for the case when there is 5 buttons in the layout.                                                                                                                                                                                                                                                                                                                        |

## Constants

### FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY

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

```
const val FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY = 2: Int
```

Button distribution where the last row has more buttons than other rows.  

### FIVE_BUTTON_DISTRIBUTION_TOP_HEAVY

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

```
const val FIVE_BUTTON_DISTRIBUTION_TOP_HEAVY = 1: Int
```

Button distribution where the first row has more buttons than other rows.  

## 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): MultiButtonLayout?
```

Returns MultiButtonLayout 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 MultiButtonLayout. Otherwise, it will return null.  

### getButtonContents

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

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

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

### getFiveButtonDistribution

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

```
fun getFiveButtonDistribution(): Int
```

Gets the button distribution from this layout for the case when there is 5 buttons in the layout. If there is more or less buttons than 5, default[FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/MultiButtonLayout#FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY())will be returned.