# ItemAlignmentFacet

# ItemAlignmentFacet

Artifact:[androidx.leanback:leanback-grid](https://developer.android.com/jetpack/androidx/releases/leanback)  
[View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/ItemAlignmentFacet.java+class:androidx.leanback.widget.ItemAlignmentFacet)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet "View this page in Java")

<br />

```
class ItemAlignmentFacet
```

<br />

*** ** * ** ***

Optional facet provided by[androidx.recyclerview.widget.RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)or[androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)for use in[HorizontalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/HorizontalGridView)and[VerticalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/VerticalGridView).

ItemAlignmentFacet contains single or multiple[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)s. First[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)describes the default alignment position for ViewHolder, it also overrides the default item alignment settings on[VerticalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/VerticalGridView)and[HorizontalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/HorizontalGridView)(see[setItemAlignmentOffset](https://developer.android.com/reference/kotlin/androidx/leanback/widget/BaseGridView#setItemAlignmentOffset(int))etc). One ItemAlignmentFacet can have multiple[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)s, e.g. having two aligned positions when child1 gets focus or child2 gets focus. Grid view will visit focused view and its ancestors till the root of ViewHolder to match[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)s'[getItemAlignmentFocusViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentFocusViewId()). Once a match found, the[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)is used to calculate alignment position.

## Summary

|                                                                                               ### Nested types                                                                                               |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[ItemAlignmentFacet.ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef) Definition of an alignment position under a view. |

|                                      ### Constants                                      |
|-----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [ITEM_ALIGN_OFFSET_PERCENT_DISABLED](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#ITEM_ALIGN_OFFSET_PERCENT_DISABLED())` = -1.0f` Value indicates that percent is not used. |

|                                                          ### Public constructors                                                          |
|-------------------------------------------------------------------------------------------------------------------------------------------|
| [ItemAlignmentFacet](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#ItemAlignmentFacet())`()` |

|                                                                                                           ### Public functions                                                                                                           |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ItemAlignmentFacet.ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)`!>` | [getAlignmentDefs](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#getAlignmentDefs())`()` Returns read only definitions of alignment positions.                                                                                                                                                                                                                                                                                                |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                                                      | [isMultiAlignment](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#isMultiAlignment())`()`                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                            | [setAlignmentDefs](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#setAlignmentDefs(androidx.leanback.widget.ItemAlignmentFacet.ItemAlignmentDef[]))`(defs: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ItemAlignmentFacet.ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)`!>)` Sets definitions of alignment positions. |

## Constants

### ITEM_ALIGN_OFFSET_PERCENT_DISABLED

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

```
const val ITEM_ALIGN_OFFSET_PERCENT_DISABLED = -1.0f: Float
```

Value indicates that percent is not used. Equivalent to 0.  

## Public constructors

### ItemAlignmentFacet

Added in 1.0.0  

```
ItemAlignmentFacet()
```  

## Public functions

### getAlignmentDefs

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

```
fun getAlignmentDefs(): Array<ItemAlignmentFacet.ItemAlignmentDef!>
```

Returns read only definitions of alignment positions.  

### isMultiAlignment

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

```
fun isMultiAlignment(): Boolean
```  

### setAlignmentDefs

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

```
fun setAlignmentDefs(defs: Array<ItemAlignmentFacet.ItemAlignmentDef!>): Unit
```

Sets definitions of alignment positions.