# PrimaryLayout.Builder

# PrimaryLayout.Builder

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

<br />

```
class PrimaryLayout.Builder
```

<br />

*** ** * ** ***

Builder class for[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout).

## Summary

|                                                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#Builder(androidx.wear.protolayout.DeviceParametersBuilders.DeviceParameters))`(deviceParameters: `[DeviceParametersBuilders.DeviceParameters](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DeviceParametersBuilders.DeviceParameters)`)` Creates a builder for the[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)from the given content. |

|                                                           ### Public functions                                                           |
|------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)                 | [build](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#build())`()` Constructs and returns[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)with the provided content and look.                                                                                                                                                                                                                                                                                                                           |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(content: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Sets the additional content to this layout, above the primary chip.                                                                                                                                                                                                    |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setPrimaryChipContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setPrimaryChipContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(compactChip: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Sets the element which is in the slot at the bottom of the layout.                                                                                                                                                                           |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setPrimaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setPrimaryLabelTextContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(` ` primaryLabelText: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement) `)` Sets the content in the primary label slot which will be above the main content.                                                                                                                                         |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setResponsiveContentInsetEnabled](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setResponsiveContentInsetEnabled(boolean))`(enabled: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Changes this[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)to use responsive insets for its content (primary label, secondary label and primary bottom chip) by adding an additional space on the side of this element to avoid that content going off the screen edge. |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setSecondaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setSecondaryLabelTextContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(` ` secondaryLabelText: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement) `)` Sets the content in the primary label slot which will be below the main content.                                                                                                                                   |
| [PrimaryLayout.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder) | [setVerticalSpacerHeight](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setVerticalSpacerHeight(float))`(height: @`[Dimension](https://developer.android.com/reference/kotlin/androidx/annotation/Dimension)`(unit = 0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the vertical spacer height which is used as a space between main content and secondary label if there is any.                                                                                                                                                 |

## Public constructors

### Builder

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

```
Builder(deviceParameters: DeviceParametersBuilders.DeviceParameters)
```

Creates a builder for the[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)from the given content. Content inside of it can later be set with[setContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)),[setPrimaryChipContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setPrimaryChipContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)),[setPrimaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setPrimaryLabelTextContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))and[setSecondaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setSecondaryLabelTextContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)).

For optimal layouts across different screen sizes, it is highly recommended to call[setResponsiveContentInsetEnabled](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout.Builder#setResponsiveContentInsetEnabled(boolean)).  

## Public functions

### build

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

```
fun build(): PrimaryLayout
```

Constructs and returns[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)with the provided content and look.  

### setContent

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

```
fun setContent(content: LayoutElementBuilders.LayoutElement): PrimaryLayout.Builder
```

Sets the additional content to this layout, above the primary chip.

The content slot will wrap the elements' height, so the height of the given content must be fixed or set to wrap (`expand`can't be used).

This layout has built-in horizontal margins, so the given content should have width set to`expand`to use all the available space, rather than an explicit width which may lead to clipping.  

### setPrimaryChipContent

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

```
fun setPrimaryChipContent(compactChip: LayoutElementBuilders.LayoutElement): PrimaryLayout.Builder
```

Sets the element which is in the slot at the bottom of the layout. Note that it is accepted to pass in any[LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement), but it is strongly recommended to add a[CompactChip](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/CompactChip)as the layout is optimized for it.  

### setPrimaryLabelTextContent

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

```
fun setPrimaryLabelTextContent(
    primaryLabelText: LayoutElementBuilders.LayoutElement
): PrimaryLayout.Builder
```

Sets the content in the primary label slot which will be above the main content.  

### setResponsiveContentInsetEnabled

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

```
fun setResponsiveContentInsetEnabled(enabled: Boolean): PrimaryLayout.Builder
```

Changes this[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)to use responsive insets for its content (primary label, secondary label and primary bottom chip) by adding an additional space on the side of this element to avoid that content going off the screen edge.

It is highly recommended to call this method with`true`when using this layout to optimize it for different screen sizes.  

### setSecondaryLabelTextContent

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

```
fun setSecondaryLabelTextContent(
    secondaryLabelText: LayoutElementBuilders.LayoutElement
): PrimaryLayout.Builder
```

Sets the content in the primary label slot which will be below the main content. It is highly recommended to have primary label set when having secondary label.  

### setVerticalSpacerHeight

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

```
fun setVerticalSpacerHeight(height: @Dimension(unit = 0) Float): PrimaryLayout.Builder
```

Sets the vertical spacer height which is used as a space between main content and secondary label if there is any. If not set,[DEFAULT_VERTICAL_SPACER_HEIGHT](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/LayoutDefaults#DEFAULT_VERTICAL_SPACER_HEIGHT())will be used.