列表具體item

2024-01-22 17:53 更新

用來展示列表具體item,必須配合List來使用。

說明

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

子組件

可以包含單個子組件。

接口

ListItem(value?: string)

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

屬性

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

名稱

參數(shù)類型

描述

sticky(deprecated)

Sticky

設(shè)置ListItem吸頂效果。

默認值:Sticky.None

從API version9開始廢棄,推薦使用List組件sticky屬性。

editable(deprecated)

boolean | EditMode

當前ListItem元素是否可編輯,進入編輯模式后可刪除或移動列表項。

從API version9開始廢棄。

默認值:false

selectable8+

boolean

當前ListItem元素是否可以被鼠標框選。

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

說明:

外層List容器的鼠標框選開啟時,ListItem的框選才生效。

默認值:true

swipeAction9+

{

start?: CustomBuilder,

end?:CustomBuilder,

edgeEffect?: SwipeEdgeEffect,

}

用于設(shè)置ListItem的劃出組件。

- start: ListItem向右劃動時item左邊的組件(List垂直布局時)或ListItem向下劃動時item上方的組件(List水平布局時)。

- end: ListItem向左劃動時item右邊的組件(List垂直布局時)或ListItem向上劃動時item下方的組件(List水平布局時)。

- edgeEffect: 滑動效果。

說明:

start和end對應(yīng)的@builder函數(shù)中頂層必須是單個組件,不能是if/else、ForEach、LazyForEach語句。

Sticky(deprecated)枚舉說明

從API version9開始廢棄,推薦使用List組件stickyStyle枚舉

名稱

描述

None

無吸頂效果。

Normal

當前item吸頂。

Opacity

當前item吸頂顯示透明度變化效果。

EditMode枚舉說明

名稱

描述

None

編輯操作不限制。

Deletable

可刪除。

Movable

可移動。

SwipeEdgeEffect9+枚舉說明

名稱

描述

Spring

ListItem劃動距離超過劃出組件大小后可以繼續(xù)劃動,松手后按照彈簧阻尼曲線回彈。

None

ListItem劃動距離不能超過劃出組件大小。

事件

名稱

功能描述

onSelect(event: (isSelected: boolean) => void)8+

ListItem元素被鼠標框選的狀態(tài)改變時觸發(fā)回調(diào)。

isSelected:進入鼠標框選范圍即被選中返回true, 移出鼠標框選范圍即未被選中返回false。

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

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct ListItemExample {
  5. private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  6. build() {
  7. Column() {
  8. List({ space: 20, initialIndex: 0 }) {
  9. ForEach(this.arr, (item) => {
  10. ListItem() {
  11. Text('' + item)
  12. .width('100%').height(100).fontSize(16)
  13. .textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF)
  14. }
  15. }, item => item)
  16. }.width('90%')
  17. }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  18. }
  19. }

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct ListItemExample2 {
  5. @State message: string = 'Hello World'
  6. @Builder itemEnd() {
  7. Row () {
  8. Button("Del").margin("4vp")
  9. Button("Set").margin("4vp")
  10. }.padding("4vp").justifyContent(FlexAlign.SpaceEvenly)
  11. }
  12. build() {
  13. Column() {
  14. List({space:10}) {
  15. ListItem() {
  16. Text(this.message)
  17. .width('100%')
  18. .height(100)
  19. .fontSize(16)
  20. .textAlign(TextAlign.Center)
  21. .borderRadius(10)
  22. .backgroundColor(0xFFFFFF)
  23. }
  24. .swipeAction({ end:this.itemEnd})
  25. ListItem() {
  26. Text(this.message)
  27. .width('100%')
  28. .height(100)
  29. .fontSize(16)
  30. .textAlign(TextAlign.Center)
  31. .borderRadius(10)
  32. .backgroundColor(0xFFFFFF)
  33. }
  34. .swipeAction({ start:this.itemEnd})
  35. }
  36. }
  37. .padding(10)
  38. .backgroundColor(0xDCDCDC)
  39. .width('100%')
  40. .height('100%')
  41. }
  42. }

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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號