ButtonGroupKt

Added in 1.3.0-alpha04

public final class ButtonGroupKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.LayoutElement
buttonGroup(
    @NonNull MaterialScope receiver,
    @NonNull DimensionBuilders.ContainerDimension width,
    @NonNull DimensionBuilders.ContainerDimension height,
    @Dimension(unit = 0) float spacing,
    @ExtensionFunctionType @NonNull Function1<@NonNull ButtonGroupScopeUnit> content
)

ProtoLayout Material3 component-layout that places its children in a horizontal sequence.

Public methods

public static final @NonNull LayoutElementBuilders.LayoutElement buttonGroup(
    @NonNull MaterialScope receiver,
    @NonNull DimensionBuilders.ContainerDimension width,
    @NonNull DimensionBuilders.ContainerDimension height,
    @Dimension(unit = 0) float spacing,
    @ExtensionFunctionType @NonNull Function1<@NonNull ButtonGroupScopeUnit> content
)

ProtoLayout Material3 component-layout that places its children in a horizontal sequence.

These behave as a group which fill the available space to maximize on screen real estate. The color and size of the child elements should be changed in order to create hierarchy and priority.

The width and height of the Button/Card should be flexible (set to androidx.wear.protolayout.DimensionBuilders.expand or androidx.wear.protolayout.DimensionBuilders.weight) and their proportion should be either equal or weight based. However the buttonGroup displays correctly too if the sizes of elements provided are set to a fixed width/height, although it can lead to more empty space on large screen sizes.

A buttonGroup with more than one row can be created by using multiple buttonGroup and Spacers inside a androidx.wear.protolayout.LayoutElementBuilders.Column:

Column.Builder()
.setWidth(expand())
.setHeight(expand())
.addContent(buttonGroup {...})
.addContent(DEFAULT_SPACER_BETWEEN_BUTTON_GROUPS)
.addContent(buttonGroup {...})
.build()
}

Note that, having more than 2 rows in a Column could lead to too small height of elements that aren't in line with minimum tap target.

Parameters
@NonNull DimensionBuilders.ContainerDimension width

The width of this button group

@NonNull DimensionBuilders.ContainerDimension height

The height of this button group

@Dimension(unit = 0) float spacing

The amount of spacing between buttons

@ExtensionFunctionType @NonNull Function1<@NonNull ButtonGroupScopeUnit> content

The content for each child. The UX guidance is to use no more than 3 elements within a this button group.