androidx.glance.layout

Interfaces

ColumnScope

Scope defining modifiers only available on rows.

RowScope

Scope defining modifiers only available on rows.

Classes

Alignment

A class used to specify the position of a sized box inside an available space.

Alignment.Horizontal

Specifies how a parent should lay its children out horizontally, if the child has a width smaller than the parent.

Alignment.Vertical

Specifies how a parent should lay its children out vertically, if the child has a height smaller than the parent.

ContentScale

Scaling to be used when an element is smaller than its available bounds.

Top-level functions summary

Unit
@Composable
Box(
    modifier: GlanceModifier,
    contentAlignment: Alignment,
    content: @Composable () -> Unit
)

A layout composable with content.

Unit
@Composable
Column(
    modifier: GlanceModifier,
    verticalAlignment: Alignment.Vertical,
    horizontalAlignment: Alignment.Horizontal,
    content: @Composable ColumnScope.() -> Unit
)

A layout composable with content, which lays its children out in a Column.

Unit
@Composable
Row(
    modifier: GlanceModifier,
    horizontalAlignment: Alignment.Horizontal,
    verticalAlignment: Alignment.Vertical,
    content: @Composable RowScope.() -> Unit
)

A layout composable with content, which lays its children out in a Row.

Unit

Component that represents an empty space layout, whose size can be defined using GlanceModifier.width, GlanceModifier.height, GlanceModifier.size modifiers.

Extension functions summary

GlanceModifier
GlanceModifier.absolutePadding(left: Dp, top: Dp, right: Dp, bottom: Dp)

Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.

GlanceModifier
GlanceModifier.absolutePadding(
    left: @DimenRes Int,
    top: @DimenRes Int,
    right: @DimenRes Int,
    bottom: @DimenRes Int
)

Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.

GlanceModifier

Specifies that the height of the element should expand to the size of its parent.

GlanceModifier

Set both the width and height to the maximum available space.

GlanceModifier

Specifies that the width of the element should expand to the size of its parent.

GlanceModifier

Sets the absolute height of an element, in Dp.

GlanceModifier

Set the height of the view from a resource.

GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

GlanceModifier
GlanceModifier.padding(horizontal: Dp, vertical: Dp)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

GlanceModifier
GlanceModifier.padding(horizontal: @DimenRes Int, vertical: @DimenRes Int)

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

GlanceModifier
GlanceModifier.padding(start: Dp, top: Dp, end: Dp, bottom: Dp)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

GlanceModifier
GlanceModifier.padding(
    start: @DimenRes Int,
    top: @DimenRes Int,
    end: @DimenRes Int,
    bottom: @DimenRes Int
)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

GlanceModifier

Sets both the width and height of an element, in Dp.

GlanceModifier

Sets both width and height of an element from a resource.

GlanceModifier
GlanceModifier.size(width: Dp, height: Dp)

Sets both the width and height of an element, in Dp.

GlanceModifier
GlanceModifier.size(width: @DimenRes Int, height: @DimenRes Int)

Sets both the width and height of an element from resources.

GlanceModifier

Sets the absolute width of an element, in Dp.

GlanceModifier

Set the width of a view from the value of a resource.

GlanceModifier

Specifies that the height of the element should wrap its contents.

GlanceModifier

Wrap both the width and height's content.

GlanceModifier

Specifies that the width of the element should wrap its contents.

Top-level functions

Box

@Composable
fun Box(
    modifier: GlanceModifier = GlanceModifier,
    contentAlignment: Alignment = Alignment.TopStart,
    content: @Composable () -> Unit
): Unit

A layout composable with content.

By default, the Box will size itself to fit the content, unless a Dimension constraint has been provided. When the children are smaller than the Box, they will be placed within the box subject to the contentAlignment. When the content has more than one layout child, all of the children will be stacked on top of each other in the composition order.

Note for App Widgets: Box supports up to 10 child elements. Any additional elements will be truncated from the output.

Parameters
modifier: GlanceModifier = GlanceModifier

The modifier to be applied to the layout.

contentAlignment: Alignment = Alignment.TopStart

The alignment of children within the Box.

content: @Composable () -> Unit

The content inside the Box.

@Composable
fun Column(
    modifier: GlanceModifier = GlanceModifier,
    verticalAlignment: Alignment.Vertical = Alignment.Top,
    horizontalAlignment: Alignment.Horizontal = Alignment.Start,
    content: @Composable ColumnScope.() -> Unit
): Unit

A layout composable with content, which lays its children out in a Column.

By default, the Column will size itself to fit the content, unless a Dimension constraint has been provided. When children are smaller than the size of the Column, they will be placed within the available space subject to horizontalAlignment and verticalAlignment.

Note for App Widgets: Column supports up to 10 child elements. Any additional elements will be truncated from the output.

Parameters
modifier: GlanceModifier = GlanceModifier

The modifier to be applied to the layout.

verticalAlignment: Alignment.Vertical = Alignment.Top

The vertical alignment to apply to the set of children, when they do not consume the full height of the Column (i.e. whether to push the children towards the top, center or bottom of the Column).

horizontalAlignment: Alignment.Horizontal = Alignment.Start

The horizontal alignment to apply to children when they are smaller than the width of the Column

content: @Composable ColumnScope.() -> Unit

The content inside the Column

@Composable
fun Row(
    modifier: GlanceModifier = GlanceModifier,
    horizontalAlignment: Alignment.Horizontal = Alignment.Start,
    verticalAlignment: Alignment.Vertical = Alignment.Top,
    content: @Composable RowScope.() -> Unit
): Unit

A layout composable with content, which lays its children out in a Row.

By default, the Row will size itself to fit the content, unless a Dimension constraint has been provided. When children are smaller than the size of the Row, they will be placed within the available space subject to verticalAlignment and horizontalAlignment.

Note for App Widgets: Row supports up to 10 child elements. Any additional elements will be truncated from the output.

Parameters
modifier: GlanceModifier = GlanceModifier

The modifier to be applied to the layout.

horizontalAlignment: Alignment.Horizontal = Alignment.Start

The horizontal alignment to apply to the set of children, when they do not consume the full width of the Row (i.e. whether to push the children towards the start, center or end of the Row).

verticalAlignment: Alignment.Vertical = Alignment.Top

The horizontal alignment to apply to children when they are smaller than the height of the Row

content: @Composable RowScope.() -> Unit

The content inside the Row

Spacer

@Composable
fun Spacer(modifier: GlanceModifier = GlanceModifier): Unit

Component that represents an empty space layout, whose size can be defined using GlanceModifier.width, GlanceModifier.height, GlanceModifier.size modifiers.

Parameters
modifier: GlanceModifier = GlanceModifier

Modifiers to set to this spacer

Extension functions

absolutePadding

fun GlanceModifier.absolutePadding(
    left: Dp = 0.dp,
    top: Dp = 0.dp,
    right: Dp = 0.dp,
    bottom: Dp = 0.dp
): GlanceModifier

Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.

absolutePadding

fun GlanceModifier.absolutePadding(
    left: @DimenRes Int = 0,
    top: @DimenRes Int = 0,
    right: @DimenRes Int = 0,
    bottom: @DimenRes Int = 0
): GlanceModifier

Apply additional space along each edge of the content in Dp: left, top, right and bottom, ignoring the current locale's layout direction.

fillMaxHeight

fun GlanceModifier.fillMaxHeight(): GlanceModifier

Specifies that the height of the element should expand to the size of its parent. Note that if multiple elements within a linear container (e.g. Row or Column) have their height as expandHeight, then they will all share the remaining space.

fillMaxSize

fun GlanceModifier.fillMaxSize(): GlanceModifier

Set both the width and height to the maximum available space.

fillMaxWidth

fun GlanceModifier.fillMaxWidth(): GlanceModifier

Specifies that the width of the element should expand to the size of its parent. Note that if multiple elements within a linear container (e.g. Row or Column) have their width as fillMaxWidth, then they will all share the remaining space.

fun GlanceModifier.height(height: Dp): GlanceModifier

Sets the absolute height of an element, in Dp.

height

fun GlanceModifier.height(height: @DimenRes Int): GlanceModifier

Set the height of the view from a resource.

fun GlanceModifier.padding(all: Dp): GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

padding

fun GlanceModifier.padding(all: @DimenRes Int): GlanceModifier

Apply all dp of additional space along each edge of the content, left, top, right and bottom.

fun GlanceModifier.padding(horizontal: Dp = 0.dp, vertical: Dp = 0.dp): GlanceModifier

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.

padding

fun GlanceModifier.padding(horizontal: @DimenRes Int = 0, vertical: @DimenRes Int = 0): GlanceModifier

Apply horizontal dp space along the left and right edges of the content, and vertical dp space along the top and bottom edges.

If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.

fun GlanceModifier.padding(
    start: Dp = 0.dp,
    top: Dp = 0.dp,
    end: Dp = 0.dp,
    bottom: Dp = 0.dp
): GlanceModifier

Apply additional space along each edge of the content in Dp: start, top, end and bottom. The start and end edges will be determined by layout direction of the current locale. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.

padding

fun GlanceModifier.padding(
    start: @DimenRes Int = 0,
    top: @DimenRes Int = 0,
    end: @DimenRes Int = 0,
    bottom: @DimenRes Int = 0
): GlanceModifier

Apply additional space along each edge of the content in Dp: start, top, end and bottom. The start and end edges will be determined by layout direction of the current locale. Padding is applied before content measurement and takes precedence; content may only be as large as the remaining space.

If any value is not defined, it will be 0.dp or whatever value was defined by an earlier modifier.

fun GlanceModifier.size(size: Dp): GlanceModifier

Sets both the width and height of an element, in Dp.

size

fun GlanceModifier.size(size: @DimenRes Int): GlanceModifier

Sets both width and height of an element from a resource.

fun GlanceModifier.size(width: Dp, height: Dp): GlanceModifier

Sets both the width and height of an element, in Dp.

size

fun GlanceModifier.size(width: @DimenRes Int, height: @DimenRes Int): GlanceModifier

Sets both the width and height of an element from resources.

fun GlanceModifier.width(width: Dp): GlanceModifier

Sets the absolute width of an element, in Dp.

width

fun GlanceModifier.width(width: @DimenRes Int): GlanceModifier

Set the width of a view from the value of a resource.

wrapContentHeight

fun GlanceModifier.wrapContentHeight(): GlanceModifier

Specifies that the height of the element should wrap its contents.

wrapContentSize

fun GlanceModifier.wrapContentSize(): GlanceModifier

Wrap both the width and height's content.

wrapContentWidth

fun GlanceModifier.wrapContentWidth(): GlanceModifier

Specifies that the width of the element should wrap its contents.