{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ColumnKt

public final class ColumnKt


Summary

Public methods

static final void
@Composable
Column(
    @NonNull Modifier modifier,
    @NonNull Arrangement.Vertical verticalArrangement,
    @NonNull Alignment.Horizontal horizontalAlignment,
    @Composable @ExtensionFunctionType @NonNull Function1<@NonNull ColumnScopeUnit> content
)

A layout composable that places its children in a vertical sequence.

Public methods

Column

@Composable
public static final void Column(
    @NonNull Modifier modifier,
    @NonNull Arrangement.Vertical verticalArrangement,
    @NonNull Alignment.Horizontal horizontalAlignment,
    @Composable @ExtensionFunctionType @NonNull Function1<@NonNull ColumnScopeUnit> content
)

A layout composable that places its children in a vertical sequence. For a layout composable that places its children in a horizontal sequence, see Row. Note that by default items do not scroll; see Modifier.verticalScroll to add this behavior. For a vertically scrollable list that only composes and lays out the currently visible items see LazyColumn.

The Column layout is able to assign children heights according to their weights provided using the ColumnScope.weight modifier. If a child is not provided a weight, it will be asked for its preferred height before the sizes of the children with weights are calculated proportionally to their weight based on the remaining available space. Note that if the Column is vertically scrollable or part of a vertically scrollable container, any provided weights will be disregarded as the remaining available space will be infinite.

When none of its children have weights, a Column will be as small as possible to fit its children one on top of the other. In order to change the height of the Column, use the Modifier.height modifiers; e.g. to make it fill the available height Modifier.fillMaxHeight can be used. If at least one child of a Column has a weight, the Column will fill the available height, so there is no need for Modifier.fillMaxHeight. However, if Column's size should be limited, the Modifier.height or Modifier.size layout modifiers should be applied.

When the size of the Column is larger than the sum of its children sizes, a verticalArrangement can be specified to define the positioning of the children inside the Column. See Arrangement for available positioning behaviors; a custom arrangement can also be defined using the constructor of Arrangement. Below is an illustration of different vertical arrangements:

Column arrangements

Example usage:

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

Column {
    // The child with no weight will have the specified size.
    Box(Modifier.size(40.dp, 80.dp).background(Color.Magenta))
    // Has weight, the child will occupy half of the remaining height.
    Box(Modifier.width(40.dp).weight(1f).background(Color.Yellow))
    // Has weight and does not fill, the child will occupy at most half of the remaining height.
    // Therefore it will occupy 80.dp (its preferred height) if the assigned height is larger.
    Box(
        Modifier.size(40.dp, 80.dp)
            .weight(1f, fill = false)
            .background(Color.Green)
    )
}
Parameters
@NonNull Modifier modifier

The modifier to be applied to the Column.

@NonNull Arrangement.Vertical verticalArrangement

The vertical arrangement of the layout's children.

@NonNull Alignment.Horizontal horizontalAlignment

The horizontal alignment of the layout's children.

See also
Row
LazyColumn