文档管理中心
您当前浏览的HarmonyOS 5.0.0(API 12)文档归档不再维护,推荐您使用最新版本。详细请参考文档维护策略变更
API参考应用框架ArkUI(方舟UI框架)ArkTS组件空白与分隔Divider

Divider

提供分隔器组件,分隔不同内容块/内容元素。

说明

该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

子组件

接口

Divider()

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

属性

除支持通用属性外,还支持以下属性:

vertical

vertical(value: boolean)

设置分割线的方向。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value boolean

使用水平分割线还是垂直分割线。

false:水平分割线;true:垂直分割线。

默认值:false

color

color(value: ResourceColor)

设置分割线的颜色。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value ResourceColor

分割线颜色。

默认值:'#33182431'

支持通过WithTheme设置通用分割线颜色

strokeWidth

strokeWidth(value: number | string)

设置分割线的宽度。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value number | string

分割线宽度。

默认值:1px

单位:vp

说明:

分割线的宽度不支持百分比设置。优先级低于通用属性height,超过通用属性设置大小时,按照通用属性进行裁切。部分设备硬件中存在1像素取整后分割线不显示问题,建议使用2像素。

lineCap

lineCap(value: LineCapStyle)

设置分割线的端点样式。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value LineCapStyle

分割线的端点样式。

默认值:LineCapStyle.Butt

示例

定义了Divider的样式,如方向、颜色及宽度。

收起
自动换行
深色代码主题
复制
  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct DividerExample {
  5. build() {
  6. Column() {
  7. // 使用横向分割线场景
  8. Text('Horizontal divider').fontSize(9).fontColor(0xCCCCCC)
  9. List() {
  10. ForEach([1, 2, 3], (item: number) => {
  11. ListItem() {
  12. Text('list' + item).width('100%').fontSize(14).fontColor('#182431').textAlign(TextAlign.Start)
  13. }.width(244).height(48)
  14. }, (item: number) => item.toString())
  15. }.padding({ left: 24, bottom: 8 })
  16. Divider().strokeWidth(8).color('#F1F3F5')
  17. List() {
  18. ForEach([4, 5], (item: number) => {
  19. ListItem() {
  20. Text('list' + item).width('100%').fontSize(14).fontColor('#182431').textAlign(TextAlign.Start)
  21. }.width(244).height(48)
  22. }, (item: number) => item.toString())
  23. }.padding({ left: 24, top: 8 })
  24. // 使用纵向分割线场景
  25. Text('Vertical divider').fontSize(9).fontColor(0xCCCCCC)
  26. Column() {
  27. Column() {
  28. Row().width(288).height(64).backgroundColor('#30C9F0').opacity(0.3)
  29. Row() {
  30. Button('Button')
  31. .width(136)
  32. .height(22)
  33. .fontSize(16)
  34. .fontColor('#007DFF')
  35. .fontWeight(500)
  36. .backgroundColor(Color.Transparent)
  37. Divider().vertical(true).height(22).color('#182431').opacity(0.6).margin({ left: 8, right: 8 })
  38. Button('Button')
  39. .width(136)
  40. .height(22)
  41. .fontSize(16)
  42. .fontColor('#007DFF')
  43. .fontWeight(500)
  44. .backgroundColor(Color.Transparent)
  45. }.margin({ top: 17 })
  46. }
  47. .width(336)
  48. .height(152)
  49. .backgroundColor('#FFFFFF')
  50. .borderRadius(24)
  51. .padding(24)
  52. }
  53. .width('100%')
  54. .height(168)
  55. .backgroundColor('#F1F3F5')
  56. .justifyContent(FlexAlign.Center)
  57. .margin({ top: 8 })
  58. }.width('100%').padding({ top: 24 })
  59. }
  60. }

在 API参考 中进行搜索
请输入您想要搜索的关键词