列表item分組

2024-01-22 17:54 更新

該組件用來展示列表item分組,寬度默認(rèn)充滿List組件,必須配合List組件來使用。

說明

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

使用說明

當(dāng)ListItemGroup的父組件List的listDirection屬性為Axis.Vertical時(shí),不允許設(shè)置ListItemGroup組件的height屬性。

ListItemGroup的高度為header高度、footer高度和所有ListItem布局后總高度之和。當(dāng)父組件List的listDirection屬性為Axis.Horizontal時(shí),不允許設(shè)置ListItemGroup組件的width屬性。ListItemGroup的寬度為header寬度、footer寬度和所有ListItem布局后總寬度之和。

當(dāng)前ListItemGroup內(nèi)部的ListItem組件不支持編輯、框選、拖拽功能,即ListItem組件的editable、selectable屬性不生效。

子組件

包含ListItem子組件。

接口

ListItemGroup(options?: {header?: CustomBuilder, footer?: CustomBuilder, space?: number | string})

參數(shù):

參數(shù)名

參數(shù)類型

必填

參數(shù)描述

header

CustomBuilder

設(shè)置ListItemGroup頭部組件。

footer

CustomBuilder

設(shè)置ListItemGroup尾部組件。

space

number | string

列表項(xiàng)間距。只作用于ListItem與ListItem之間,不作用于header與ListItem、footer與ListItem之間。

屬性

名稱

參數(shù)類型

描述

divider

{

strokeWidth: Length,

color?: ResourceColor,

startMargin?: Length,

endMargin?: Length

} | null

用于設(shè)置ListItem分割線樣式,默認(rèn)無分割線。

strokeWidth: 分割線的線寬。

color: 分割線的顏色。

startMargin: 分割線距離列表側(cè)邊起始端的距離。

endMargin: 分割線距離列表側(cè)邊結(jié)束端的距離。

strokeWidth, startMargin和endMargin不支持設(shè)置百分比。

說明

ListItemGroup組件不支持設(shè)置通用屬性aspectRatio

ListItemGroup組件如果主軸方向是垂直方向時(shí),設(shè)置通用屬性height屬性不生效。

ListItemGroup組件如果主軸方向是水平方向時(shí),設(shè)置通用屬性width屬性不生效。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct ListItemGroupExample {
  5. private timetable: any = [
  6. {
  7. title:'星期一',
  8. projects:['語文', '數(shù)學(xué)', '英語']
  9. },
  10. {
  11. title:'星期二',
  12. projects:['物理', '化學(xué)', '生物']
  13. },
  14. {
  15. title:'星期三',
  16. projects:['歷史', '地理', '政治']
  17. },
  18. {
  19. title:'星期四',
  20. projects:['美術(shù)', '音樂', '體育']
  21. }
  22. ]
  23. @Builder itemHead(text:string) {
  24. Text(text)
  25. .fontSize(20)
  26. .backgroundColor(0xAABBCC)
  27. .width("100%")
  28. .padding(10)
  29. }
  30. @Builder itemFoot(num:number) {
  31. Text('共' + num + "節(jié)課")
  32. .fontSize(16)
  33. .backgroundColor(0xAABBCC)
  34. .width("100%")
  35. .padding(5)
  36. }
  37. build() {
  38. Column() {
  39. List({ space: 20 }) {
  40. ForEach(this.timetable, (item) => {
  41. ListItemGroup({ header:this.itemHead(item.title), footer:this.itemFoot(item.projects.length) }) {
  42. ForEach(item.projects, (project) => {
  43. ListItem() {
  44. Text(project)
  45. .width("100%").height(100).fontSize(20)
  46. .textAlign(TextAlign.Center).backgroundColor(0xFFFFFF)
  47. }
  48. }, item => item)
  49. }
  50. .borderRadius(20)
  51. .divider({ strokeWidth: 1, color: Color.Blue }) // 每行之間的分界線
  52. })
  53. }
  54. .width('90%')
  55. .sticky(StickyStyle.Header|StickyStyle.Footer)
  56. }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  57. }
  58. }

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)