Gravity

object Gravity
kotlin.Any
   ↳ androidx.ui.layout.Gravity

Provides scope-dependent alignment options for children layouts where the alignment is handled by the parent layout rather than the child itself. Different layout models allow different Gravity options. For example, Row provides Top and Bottom, while Column provides Start and End. Unlike Align, layout children with Gravity are aligned only after the size of the parent is known, therefore not affecting the size of the parent in order to achieve their own alignment.

Example usage:

import androidx.ui.layout.Row

Row(ExpandedHeight) {
    // The child with no gravity modifier is positioned by default so that its top edge is
    // aligned to the top of the vertical axis.
    SizedRectangle(color = Color.Magenta, width = 80.dp, height = 40.dp)
    // Gravity.Top, the child will be positioned so that its top edge is aligned to the top
    // of the vertical axis.
    SizedRectangle(Gravity.Top, color = Color.Red, width = 80.dp, height = 40.dp)
    // Gravity.Center, the child will be positioned so that its center is in the middle of
    // the vertical axis.
    SizedRectangle(Gravity.Center, color = Color.Yellow, width = 80.dp, height = 40.dp)
    // Gravity.Bottom, the child will be positioned so that its bottom edge is aligned to the
    // bottom of the vertical axis.
    SizedRectangle(Gravity.Bottom, color = Color.Green, width = 80.dp, height = 40.dp)
}
import androidx.ui.layout.Column

Column(ExpandedWidth) {
    // The child with no gravity modifier is positioned by default so that its start edge
    // aligned with the start edge of the horizontal axis.
    SizedRectangle(color = Color.Magenta, width = 80.dp, height = 40.dp)
    // Gravity.Start, the child will be positioned so that its start edge is aligned with
    // the start edge of the horizontal axis.
    SizedRectangle(Gravity.Start, color = Color.Red, width = 80.dp, height = 40.dp)
    // Gravity.Center, the child will be positioned so that its center is in the middle of
    // the horizontal axis.
    SizedRectangle(Gravity.Center, color = Color.Yellow, width = 80.dp, height = 40.dp)
    // Gravity.End, the child will be positioned so that its end edge aligned to the end of
    // the horizontal axis.
    SizedRectangle(Gravity.End, color = Color.Green, width = 80.dp, height = 40.dp)
}

Summary

Extension properties

From androidx.ui.layout.RowScope
LayoutModifier

A layout modifier within a Row that positions target component in a vertical direction so that its bottom edge is aligned to the bottom edge of the vertical axis.

LayoutModifier

A layout modifier within a Row that positions target component in a vertical direction so that its center is in the middle of the vertical axis.

LayoutModifier

A layout modifier within a Row that positions target component in a vertical direction so that its top edge is aligned to the top edge of the vertical axis.

From androidx.ui.layout.ColumnScope
LayoutModifier

A layout modifier within a Column that positions target component in a horizontal direction so that its center is in the middle of the horizontal axis.

LayoutModifier

A layout modifier within a Column that positions target component in a horizontal direction so that its end edge is aligned to the end edge of the horizontal axis.

LayoutModifier

A layout modifier within a Column that positions target component in a horizontal direction so that its start edge is aligned to the start edge of the horizontal axis.