# ItemAlignmentFacet.ItemAlignmentDef

# ItemAlignmentFacet.ItemAlignmentDef

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

<br />

```
class ItemAlignmentFacet.ItemAlignmentDef
```

<br />

*** ** * ** ***

Definition of an alignment position under a view.

## Summary

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

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [getItemAlignmentFocusViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentFocusViewId())`()` Returns Id of which child view take focus for alignment.                                                                                                                                                                                                                                                                                                                                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [getItemAlignmentOffset](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffset())`()` Returns number of pixels to the end of low edge.                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)     | [getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())`()` Gets the offset percent for item alignment in addition to offset.                                                                                                                                                                                                                                                                                                                                                                       |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [getItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentViewId())`()` Returns Id of which child view to be aligned.                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isAlignedToTextViewBaseLine](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#isAlignedToTextViewBaseLine())`()` Returns true when View should be aligned to[getBaseline](https://developer.android.com/reference/android/view/View.html#getBaseline())                                                                                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isItemAlignmentOffsetWithPadding](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#isItemAlignmentOffsetWithPadding())`()` Returns true if applies padding to item alignment when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0 or 100; returns false otherwise.                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setAlignedToTextViewBaseline](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setAlignedToTextViewBaseline(boolean))`(alignToBaseline: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` When true, align to[getBaseline](https://developer.android.com/reference/android/view/View.html#getBaseline())for the view of with id equals[getItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentViewId()); false otherwise. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setItemAlignmentFocusViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentFocusViewId(int))`(viewId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets Id of which child view take focus for alignment.                                                                                                                                                                                                                                                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setItemAlignmentOffset](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentOffset(int))`(offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets number of pixels to the end of low edge.                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentOffsetPercent(float))`(percent: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the offset percent for item alignment in addition to offset.                                                                                                                                                                                                                                                                        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setItemAlignmentOffsetWithPadding](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentOffsetWithPadding(boolean))`(withPadding: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether applies padding to item alignment when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0 or 100.                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentViewId(int))`(viewId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets Id of which child view to be aligned.                                                                                                                                                                                                                                                                                                                    |

## Public constructors

### ItemAlignmentDef

Added in 1.0.0  

```
ItemAlignmentDef()
```  

## Public functions

### getItemAlignmentFocusViewId

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

```
fun getItemAlignmentFocusViewId(): Int
```

Returns Id of which child view take focus for alignment. When not set, it will use use same id of[getItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentViewId())  

### getItemAlignmentOffset

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

```
fun getItemAlignmentOffset(): Int
```

Returns number of pixels to the end of low edge. Supports right to left layout direction. In left to right or vertical case, it's the offset added to left/top edge. In right to left case, it's the offset subtracted from right edge.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Number of pixels to the end of low edge. |

### getItemAlignmentOffsetPercent

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

```
fun getItemAlignmentOffsetPercent(): Float
```

Gets the offset percent for item alignment in addition to offset. E.g., 40 means 40% of the width from the low edge. In the right to left case, it's the 40% from right edge. Use[ITEM_ALIGN_OFFSET_PERCENT_DISABLED](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#ITEM_ALIGN_OFFSET_PERCENT_DISABLED())to disable.  

### getItemAlignmentViewId

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

```
fun getItemAlignmentViewId(): Int
```

Returns Id of which child view to be aligned. View.NO_ID refers to root view and should be only used in first one. Different view ids of[#getAlignmentDefs()](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet)define multiple alignment steps within one itemView, e.g. there are two child views R.id.child1 and R.id.child2. App may allocated two[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)s, one with view id R.id.child1, the other with view id R.id.child2. Note this id may or may not be same as the child view that takes focus.  

|                                                                                  See also                                                                                   |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setItemAlignmentFocusViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentFocusViewId(int)) |   |

### isAlignedToTextViewBaseLine

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

```
fun isAlignedToTextViewBaseLine(): Boolean
```

Returns true when View should be aligned to[getBaseline](https://developer.android.com/reference/android/view/View.html#getBaseline())  

### isItemAlignmentOffsetWithPadding

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

```
fun isItemAlignmentOffsetWithPadding(): Boolean
```

Returns true if applies padding to item alignment when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0 or 100; returns false otherwise.

When true: Applies start/top padding when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0. Applies end/bottom padding when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 100. Does not apply padding if[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is neither 0 nor 100.

When false: does not apply padding  

### setAlignedToTextViewBaseline

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

```
fun setAlignedToTextViewBaseline(alignToBaseline: Boolean): Unit
```

When true, align to[getBaseline](https://developer.android.com/reference/android/view/View.html#getBaseline())for the view of with id equals[getItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentViewId()); false otherwise.  

|                                               Parameters                                               |
|--------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `alignToBaseline: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Boolean indicating whether to align to view baseline. |

### setItemAlignmentFocusViewId

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

```
fun setItemAlignmentFocusViewId(viewId: Int): Unit
```

Sets Id of which child view take focus for alignment. When not set, it will use use same id of[getItemAlignmentViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentViewId()).  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|-----------------------------------------------|
| `viewId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The id of child view that will be focused to. |

### setItemAlignmentOffset

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

```
fun setItemAlignmentOffset(offset: Int): Unit
```

Sets number of pixels to the end of low edge. Supports right to left layout direction.  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | In left to right or vertical case, it's the offset added to left/top edge. In right to left case, it's the offset subtracted from right edge. |

### setItemAlignmentOffsetPercent

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

```
fun setItemAlignmentOffsetPercent(percent: Float): Unit
```

Sets the offset percent for item alignment in addition to offset. E.g., 40 means 40% of width/height from the low edge. In the right to left case, it's the 40% width from right edge. Use[ITEM_ALIGN_OFFSET_PERCENT_DISABLED](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet#ITEM_ALIGN_OFFSET_PERCENT_DISABLED())to disable.  

### setItemAlignmentOffsetWithPadding

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

```
fun setItemAlignmentOffsetWithPadding(withPadding: Boolean): Unit
```

Sets whether applies padding to item alignment when[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0 or 100.

When true: Applies start/top padding if[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 0. Applies end/bottom padding if[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is 100. Does not apply padding if[getItemAlignmentOffsetPercent](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#getItemAlignmentOffsetPercent())is neither 0 nor 100.

When false: does not apply padding  

### setItemAlignmentViewId

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

```
fun setItemAlignmentViewId(viewId: Int): Unit
```

Sets Id of which child view to be aligned. View.NO_ID refers to root view and should be only used in first one. Different view ids of[#getAlignmentDefs()](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet)define multiple alignment steps within one itemView, e.g. there are two child views R.id.child1 and R.id.child2. App may allocated two[ItemAlignmentDef](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef)s, one with view id R.id.child1, the other with view id R.id.child2. Note this id may or may not be same as the child view that takes focus.  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|-----------------------------------------------|
| `viewId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The id of child view that will be aligned to. |

|                                                                                  See also                                                                                   |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setItemAlignmentFocusViewId](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemAlignmentFacet.ItemAlignmentDef#setItemAlignmentFocusViewId(int)) |   |