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

*** ** * ** ***


```
public final class ItemAlignmentFacet
```

<br />

*** ** * ** ***

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

ItemAlignmentFacet contains single or multiple `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef`s. First `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef` describes the default alignment position for ViewHolder, it also overrides the default item alignment settings on `https://developer.android.com/reference/androidx/leanback/widget/VerticalGridView` and `https://developer.android.com/reference/androidx/leanback/widget/HorizontalGridView` (see `https://developer.android.com/reference/androidx/leanback/widget/BaseGridView#setItemAlignmentOffset(int)` etc). One ItemAlignmentFacet can have multiple `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef`s' `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentFocusViewId()`. Once a match found, the `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef` is used to calculate alignment position.

## Summary

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

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet#ITEM_ALIGN_OFFSET_PERCENT_DISABLED() = -1.0f` Value indicates that percent is not used. |

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

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ItemAlignmentFacet.ItemAlignmentDef[]` | `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet#getAlignmentDefs()()` Returns read only definitions of alignment positions. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet#isMultiAlignment()()` |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ItemAlignmentFacet#setAlignmentDefs(androidx.leanback.widget.ItemAlignmentFacet.ItemAlignmentDef[])(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html ItemAlignmentFacet.ItemAlignmentDef[] defs)` 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)

```
public static final float ITEM_ALIGN_OFFSET_PERCENT_DISABLED = -1.0f
```

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

## Public constructors

### ItemAlignmentFacet

Added in 1.0.0

```
public ItemAlignmentFacet()
```

## Public methods

### getAlignmentDefs

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

```
public @NonNull ItemAlignmentFacet.ItemAlignmentDef[] getAlignmentDefs()
```

Returns read only definitions of alignment positions.

### isMultiAlignment

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

```
public boolean isMultiAlignment()
```

### setAlignmentDefs

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

```
public void setAlignmentDefs(@NonNull ItemAlignmentFacet.ItemAlignmentDef[] defs)
```

Sets definitions of alignment positions.