目录

Row

Defines a container that lays out child components horizontally. It supports setting the spacing between child components and the alignment mode, and is suitable for scenarios where multiple child components need to be arranged horizontally, such as toolbars, tab bars, and button groups.

This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.

If no width or height is set for the Row component, it adapts to the size of child components in the main axis or cross axis direction.

Child Components

Supported

APIs

[h2]Row

Row(options?: RowOptions)

Creates a horizontal linear layout container. You can set the spacing between child components.

When using multi-component nesting in complex UIs, if layout components are nested too deeply or too many components are nested, additional overhead will be incurred. It is recommended to optimize performance by removing redundant nodes, using layout boundaries to reduce layout calculations, and properly adopting rendering control syntax and layout component methods. For best practices, see Layout Optimization Guide.

Widget capability: This API can be used in ArkTS widgets since API version 9.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
options18+ RowOptions No

Configuration object of the horizontal layout, used to set the spacing between child components (unit: vp). The space attribute supports values of the number or string type. Pass this parameter when you need to customize the spacing between child components. If this parameter is not passed, the default spacing is 0.

Model restriction: This API can be used only in the stage model.

Note: Since API version 9, the space attribute does not take effect when it is set to a negative value or when justifyContent is set to FlexAlign.SpaceBetween, FlexAlign.SpaceAround, or FlexAlign.SpaceEvenly.

[h2]Row18+

Row(options?: RowOptions | RowOptionsV2)

Creates a horizontal linear layout container. You can set the spacing between child components.

When using multi-component nesting in complex UIs, if layout components are nested too deeply or too many components are nested, additional overhead will be incurred. It is recommended to optimize performance by removing redundant nodes, using layout boundaries to reduce layout calculations, and properly adopting rendering control syntax and layout component methods. For best practices, see Layout Optimization Guide.

Widget capability: This API can be used in ArkTS widgets since API version 18.

Atomic service API: This API can be used in atomic services since API version 18.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
options RowOptions | RowOptionsV2 No

Configuration object of the horizontal layout, used to set child component spacing (unit: vp), where the space attribute supports setting a value of type number, string, or Resource. When not passed, the default spacing is 0.

Note: Since API version 9, space does not take effect when it is negative or when justifyContent is set to FlexAlign.SpaceBetween, FlexAlign.SpaceAround, or FlexAlign.SpaceEvenly.

RowOptions18+

Sets the spacing between child components of the Row component.

To standardize anonymous object definitions, the element definitions here have been revised in API version 18. While starting version information is preserved for historical anonymous objects, there may be cases where the outer element's @since version number is higher than inner element's. This does not affect interface usability.

Widget capability: This API can be used in ArkTS widgets since API version 18.

Atomic service API: This API can be used in atomic services since API version 18.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
space7+ string | number No Yes

Horizontal layout element spacing.

Since API version 9, this attribute does not take effect when space is negative or justifyContent is set to FlexAlign.SpaceBetween, FlexAlign.SpaceAround, or FlexAlign.SpaceEvenly.

Default value: 0

Unit: vp

Invalid value: processed according to the default value.

Note:

The value of space is a number greater than or equal to 0, or a string that can be converted to a number. It does not support setting percentages.

Widget capability: Since API version 9, this API is supported in ArkTS widgets.

Atomic service API: Since API version 11, this API is supported in atomic services.

RowOptionsV218+

Sets the spacing between child components of the Row component. The spacing type SpaceType can be of the number, string, or Resource type.

Widget capability: This API can be used in ArkTS widgets since API version 18.

Atomic service API: This API can be used in atomic services since API version 18.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Name Type Read-Only Optional Description
space SpaceType No Yes

Horizontal layout element spacing.

Value range: greater than or equal to 0.

Since API version 9, when justifyContent is set to FlexAlign.SpaceBetween, FlexAlign.SpaceAround, or FlexAlign.SpaceEvenly, the space parameter is not effective.

Default value: 0

Unit: vp

Invalid value: the default value is used.

Note:

The value of space is a number greater than or equal to 0, or a string that can be converted to a non-negative number, or Resource type data that can be converted to a number. Setting a percentage is not supported. A negative number is treated as an invalid value and handled as the default value 0.

Attributes

In addition to the universal attributes, the following attributes are supported.

[h2]alignItems

alignItems(value: VerticalAlign)

Sets the alignment format of child components in the vertical direction. After this attribute is set, child components are aligned in the specified manner in the vertical direction. By default, child components are vertically centered.

Widget capability: This API can be used in ArkTS widgets since API version 9.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value VerticalAlign Yes

Alignment format of child components in the vertical direction.

Default value: VerticalAlign.Center

[h2]justifyContent8+

justifyContent(value: FlexAlign)

Sets the alignment format of child components in the horizontal direction. After this attribute is set, child components are aligned in the specified manner in the horizontal direction. By default, child components are aligned at the start.

Widget capability: This API can be used in ArkTS widgets since API version 9.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value FlexAlign Yes

Alignment format of child components in the horizontal direction.

Default value: FlexAlign.Start

Note: Since API version 9, the space parameter does not take effect when space is a negative number or justifyContent is set to FlexAlign.SpaceBetween, FlexAlign.SpaceAround, or FlexAlign.SpaceEvenly.

In a Row layout, if child components do not have flexShrink set, they are not shrunk by default. That is, the sum of the main axis sizes of all child components may exceed the main axis of the container. In this case, the alignment behavior of FlexAlign.Center and FlexAlign.End changes, and the start position of child components is the same as that of FlexAlign.Start.

[h2]reverse12+

reverse(isReversed: Optional<boolean>)

Sets whether to reverse the arrangement order of child components in the horizontal direction. When set to true, child components are arranged from right to left; when set to false, child components are arranged from left to right. This is applicable to scenarios where the display order of child components needs to be dynamically adjusted, such as internationalization layout adaptation.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
isReversed Optional<boolean> Yes

Whether the arrangement order of child components in the horizontal direction is reversed.

The value true means that the child components are arranged in reverse order in the horizontal direction (from right to left), and the value false means that the child components are arranged in normal order in the horizontal direction (from left to right). If the parameter value is undefined, it is treated as true, and the main axis direction is reversed.

If the reverse attribute is not set, the main axis direction is not reversed. If the reverse attribute is set and the parameter value is undefined, it is treated as the default value true, and the main axis direction is reversed. If the parameter value is false, the main axis direction is not reversed.

Since the arrangement direction of the main axis is affected by the universal direction attribute, if the direction attribute is set, when the reverse attribute is set to true, an additional reversal is always performed on the result after the direction attribute takes effect. If the reverse attribute is set to false or not set, the main axis direction is determined by the direction attribute, and no additional reversal is performed.

Events

The universal events are supported.

Examples

[h2]Example 1: Setting the Layout Attributes of the Row Component

This example demonstrates the effect of setting the layout attributes (such as the spacing and alignment mode) of the Row component.

// resources/base/element/string.json
{
  "string": [
    {
      "name": "stringSpace",
      "value": "5"
    }
  ]
}
// xxx.ets
@Entry
@Component
struct RowExample {
  build() {
    Column({ space: 5 }) {
      // Set the horizontal spacing between two adjacent child components to 5.
      Text('space').width('90%')
      Row({ space: 5 }) {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').height(107).border({ width: 1 })

      // Set the spacing between child components using the Resource type.
      Text('Resource space').width('90%')
      // Use the resource reference method to set the space attribute (supported since API 18).
      Row({ space: $r('app.string.stringSpace') }) {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').height(107).border({ width: 1 })

      // Set the vertical direction alignment of child components.
      Text('alignItems(Bottom)').width('90%')
      // Set the bottom alignment of child components.
      Row() {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').alignItems(VerticalAlign.Bottom).height('15%').border({ width: 1 })

      Text('alignItems(Center)').width('90%')
      // Set the vertical center alignment of child components.
      Row() {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').alignItems(VerticalAlign.Center).height('15%').border({ width: 1 })

      // Set the horizontal direction alignment of child components.
      Text('justifyContent(End)').width('90%')
      // Set the right alignment of child components.
      Row() {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End)

      Text('justifyContent(Center)').width('90%')
      // Set the horizontal center alignment of child components.
      Row() {
        Row().width('30%').height(50).backgroundColor(0xAFEEEE)
        Row().width('30%').height(50).backgroundColor(0x00FFFF)
      }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center)
    }.width('100%')
  }
}

[h2]Example 2: Configuring the Reverse Attribute

This example shows the effect after setting the reverse attribute of the Row component, demonstrating how to reverse the arrangement order of child components.

@Entry
@Component
struct RowReverseSample {
  build() {
    Row() {
      Text('1')
        .width(100)
        .height(50)
        .backgroundColor(0xAFEEEE)

      Text('2')
        .width(100)
        .height(50)
        .backgroundColor(0x00FFFF)
    }
    .height(100)
    .width(300)
    .border({ width: 1 })
    .reverse(true)
  }
}