# PrimaryLayout

# PrimaryLayout

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)  
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 "View this page in Java")

<br />

```
class PrimaryLayout : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout layout that represents a suggested layout style for Material ProtoLayout with the primary (compact) chip at the bottom with the given content in the center and the recommended margin and padding applied. There is a fixed slot for an optional primary label above or optional secondary label below the main content area. Visuals and design samples can be found[here](https://developer.android.com/design/ui/wear/guides/surfaces/tiles-layouts#layout-templates).

It is highly recommended that main content has max lines between 2 and 4 (dependant on labels present), i.e.: \* No labels are present: content with max 4 lines, \* 1 label is present: content with max 3 lines, \* 2 labels are present: content with max 2 lines.

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

PrimaryLayout myPl = (PrimaryLayout) box.getContents().get(0);
```
will fail.

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

```kotlin
PrimaryLayout myPl = PrimaryLayout.fromLayoutElement(box.getContents().get(0));
```

## Summary

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

|                                                                                   ### Public functions                                                                                   |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[PrimaryLayout](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout)`?`                                                | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Returns PrimaryLayout 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 PrimaryLayout. |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?`                                   | [getContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#getContent())`()` Get the inner content from this layout.                                                                                                                                                                                                                                                                                                                                                                                                        |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?`                                   | [getPrimaryChipContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#getPrimaryChipContent())`()` Get the primary chip content from this layout.                                                                                                                                                                                                                                                                                                                                                                           |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?`                                   | [getPrimaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#getPrimaryLabelTextContent())`()` Get the primary label content from this layout.                                                                                                                                                                                                                                                                                                                                                                |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?`                                   | [getSecondaryLabelTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#getSecondaryLabelTextContent())`()` Get the secondary label content from this layout.                                                                                                                                                                                                                                                                                                                                                          |
| `@`[Dimension](https://developer.android.com/reference/kotlin/androidx/annotation/Dimension)`(unit = 0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [getVerticalSpacerHeight](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#getVerticalSpacerHeight())`()` Get the vertical spacer height from this layout.                                                                                                                                                                                                                                                                                                                                                                     |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                      | [isResponsiveContentInsetEnabled](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/layouts/PrimaryLayout#isResponsiveContentInsetEnabled())`()` Returns whether the contents from this layout are using responsive inset.                                                                                                                                                                                                                                                                                                                            |

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

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

### getContent

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

```
fun getContent(): LayoutElementBuilders.LayoutElement?
```

Get the inner content from this layout.  

### getPrimaryChipContent

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

```
fun getPrimaryChipContent(): LayoutElementBuilders.LayoutElement?
```

Get the primary chip content from this layout.  

### getPrimaryLabelTextContent

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

```
fun getPrimaryLabelTextContent(): LayoutElementBuilders.LayoutElement?
```

Get the primary label content from this layout.  

### getSecondaryLabelTextContent

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

```
fun getSecondaryLabelTextContent(): LayoutElementBuilders.LayoutElement?
```

Get the secondary label content from this layout.  

### getVerticalSpacerHeight

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

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

Get the vertical spacer height from this layout.  

### isResponsiveContentInsetEnabled

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

```
fun isResponsiveContentInsetEnabled(): Boolean
```

Returns whether the contents from this layout are using responsive inset.