# AlignmentLine

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/AlignmentLine.kt+class:androidx.compose.ui.layout.AlignmentLine) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  sealed class AlignmentLine
  ```
Known direct subclasses [HorizontalAlignmentLine](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/HorizontalAlignmentLine), [VerticalAlignmentLine](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/VerticalAlignmentLine)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/HorizontalAlignmentLine` | A horizontal `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/VerticalAlignmentLine` | A vertical `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`. |

*** ** * ** ***

Defines an offset line that can be used by parent layouts to align and position their children. Text baselines are representative examples of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`s. For example, they can be used by `Row`, to align its children by baseline, or by `paddingFrom` to achieve a layout with a specific distance from the top to the baseline of the text content. `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`s can be understood as an abstraction over text baselines.

When a layout provides a value for a particular `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`, this can be read by the parents of the layout after measuring, using the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Measured#get(androidx.compose.ui.layout.AlignmentLine)` operator on the corresponding `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable` instance. Based on the position of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`, the parents can then decide the positioning of the children.

Note that when a layout provides a value for an `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`, this will be automatically inherited by the layout's parent, which will offset the value by the position of the child within itself. This way, nested layout hierarchies are able to preserve the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`s defined for deeply nested children, making it possible for non-direct parents to use these for positioning and alignment. When a layout inherits multiple values for the same `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine` from different children, the position of the line within the layout will be computed by merging the children values using the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine#merger()`. If a layout provides a value for an `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`, this will always be the position of the line, regardless of the values provided by children for the same line.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine`s cannot be created directly, please create `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/VerticalAlignmentLine` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/HorizontalAlignmentLine` instances instead.

```kotlin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.layout.HorizontalAlignmentLine
import androidx.compose.ui.layout.Layout

// Create a horizontal alignment line. Note it is not common for alignment lines to be created
// in the scope of one composable, since they are usually used across more than one function.
// We use ::min as merging strategy, which means that the parent will have the minimum of
// the values of the alignment line, when this is inherited from more than one child.
val exampleLine = remember { HorizontalAlignmentLine(::min) }

// A layout with a fixed size, and a given position for the exampleLine alignment line.
@Composable
fun LineProviderLayout(exampleLinePosition: Int) {
    val size: Int = 20
    Layout({}) { _, _ -> layout(size, size, mapOf(exampleLine to exampleLinePosition)) {} }
}

Layout({
    LineProviderLayout(exampleLinePosition = 5)
    LineProviderLayout(exampleLinePosition = 10)
}) { measurables, constraints ->
    val placeables = measurables.map { it.measure(constraints) }
    // placeables[0][line] will be 5
    // placeables[1][line] will be 10
    layout(constraints.maxWidth, constraints.maxHeight) {
        placeables[0].place(0, 3)
        placeables[1].place(constraints.maxWidth / 2, 0)
    }
}
// Note that if the parent of this Layout (the parent of AlignmentLineSample) was able to
// query its position of exampleLine (assuming this was in a shared scope), its position would
// be 8. This is because the Layout positioned its first child at 3 from the top,
// and because of the ::min merging strategy the position of exampleLine will be
// min(5 + 3, 10 + 0).
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/VerticalAlignmentLine` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/HorizontalAlignmentLine` |   |

## Summary

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine#Unspecified()` Constant representing that an `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine` has not been provided. | Cmn |

| ### Protected constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine#AlignmentLine(kotlin.Function2)(merger: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | Cmn |

## Constants

### Unspecified

Cmn

```
const val Unspecified: Int
```

Constant representing that an `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/AlignmentLine` has not been provided.

## Protected constructors

### AlignmentLine

Cmn

```
protected AlignmentLine(merger: (Int, Int) -> Int)
```