分隔器組件

2024-01-22 17:09 更新

提供分隔器組件,分隔不同內(nèi)容塊/內(nèi)容元素。

說明

該組件從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

子組件

接口

Divider()

從API version 9開始,該接口支持在ArkTS卡片中使用。

屬性

除支持通用屬性外,還支持以下屬性:

名稱

參數(shù)類型

描述

vertical

boolean

使用水平分割線還是垂直分割線。false:水平分割線;true:垂直分割線。

默認(rèn)值:false

從API version 9開始,該接口支持在ArkTS卡片中使用。

color

ResourceColor

分割線顏色。

默認(rèn)值:'#33182431'

從API version 9開始,該接口支持在ArkTS卡片中使用。

strokeWidth

number | string

分割線寬度。

默認(rèn)值:1

單位:vp

從API version 9開始,該接口支持在ArkTS卡片中使用。

說明:

分割線的寬度不支持百分比設(shè)置。優(yōu)先級低于通用屬性height,超過通用屬性設(shè)置大小時,按照通用屬性進(jìn)行裁切。

lineCap

LineCapStyle

分割線的端點(diǎn)樣式。

默認(rèn)值:LineCapStyle.Butt

從API version 9開始,該接口支持在ArkTS卡片中使用。

示例

  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) => {
  11. ListItem() {
  12. Text('list' + item).width('100%').fontSize(14).fontColor('#182431').textAlign(TextAlign.Start)
  13. }.width(244).height(48)
  14. }, item => item.toString())
  15. }.padding({ left: 24, bottom: 8 })
  16. Divider().strokeWidth(8).color('#F1F3F5')
  17. List() {
  18. ForEach([4, 5], (item) => {
  19. ListItem() {
  20. Text('list' + item).width('100%').fontSize(14).fontColor('#182431').textAlign(TextAlign.Start)
  21. }.width(244).height(48)
  22. }, item => 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. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號