# 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)

*** ** * ** ***


```
public class MultiButtonLayout implements LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

Opinionated ProtoLayout layout, that can contain between 1 and `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/PrimaryLayout`, but if there is `https://developer.android.com/reference/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.:

```
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 `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout` object from any layout element, `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)` method should be used, i.e.:

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

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout.Builder` Builder class for `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout`. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout#FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY() = 2` Button distribution where the last row has more buttons than other rows. |
| `static final int` | `https://developer.android.com/reference/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 methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout` | `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement element)` 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. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement>` | `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout#getButtonContents()()` Gets the content from this layout, containing all buttons that were added. |
| `int` | `https://developer.android.com/reference/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)

```
public static final int FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY = 2
```

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)

```
public static final int FIVE_BUTTON_DISTRIBUTION_TOP_HEAVY = 1
```

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

## Public methods

### fromLayoutElement

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

```
public static @Nullable MultiButtonLayout fromLayoutElement(@NonNull LayoutElementBuilders.LayoutElement element)
```

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)

```
public @NonNull List<LayoutElementBuilders.LayoutElement> getButtonContents()
```

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)

```
public int getFiveButtonDistribution()
```

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 `https://developer.android.com/reference/androidx/wear/protolayout/material/layouts/MultiButtonLayout#FIVE_BUTTON_DISTRIBUTION_BOTTOM_HEAVY()` will be returned.