0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙ArkTS容器組件:ListItemGroup

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-07-10 09:20 ? 次閱讀

ListItemGroup

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

說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

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

使用說明

當(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屬性不生效。

子組件

包含[ListItem]子組件。

接口

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

參數(shù)

參數(shù)名參數(shù)類型必填參數(shù)描述
header[CustomBuilder]設(shè)置ListItemGroup頭部組件。
footer[CustomBuilder]設(shè)置ListItemGroup尾部組件。
spacenumberstring
style10+[ListItemGroupStyle]設(shè)置List組件卡片樣式。 默認(rèn)值: ListItemGroupStyle.NONE 設(shè)置為ListItemGroupStyle.NONE時(shí)無樣式。 設(shè)置為ListItemStyle.CARD時(shí),必須配合[ListItem]的ListItemStyle.CARD同時(shí)使用,顯示默認(rèn)卡片樣式。 卡片樣式下, 為卡片內(nèi)的列表選項(xiàng)提供了默認(rèn)的focus、hover、press、selected和disable樣式。**說明:**當(dāng)前卡片模式下,不支持listDirection屬性設(shè)置,使用默認(rèn)Axis.Vertical排列方向。 當(dāng)前卡片模式下,List屬性alignListItem默認(rèn)為ListItemAlign.Center,居中對齊顯示。 當(dāng)前卡片模式下,ListItemGroup不支持設(shè)置頭部組件header和尾部組件footer。 若僅設(shè)置ListItemGroupStyle.CARD,未設(shè)置ListItemStyle.CARD時(shí),只顯示部分卡片樣式及功能。

屬性

名稱參數(shù)類型描述
divider{ strokeWidth: [Length], color?: [ResourceColor], startMargin?: [Length], endMargin?: [Length] }null

ListItemGroupStyle10+枚舉說明

名稱描述
NONE無樣式。
CARD顯示默認(rèn)卡片樣式。

說明:

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

ListItemGroup組件如果主軸方向是垂直方向時(shí),設(shè)置[通用屬性height]屬性不生效。
HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
ListItemGroup組件如果主軸方向是水平方向時(shí),設(shè)置[通用屬性width]屬性不生效。

搜狗高速瀏覽器截圖20240326151450.png

示例

// xxx.ets
@Entry
@Component
struct ListItemGroupExample {
  private timetable: TimeTable[] = [
    {
      title: '星期一',
      projects: ['語文', '數(shù)學(xué)', '英語']
    },
    {
      title: '星期二',
      projects: ['物理', '化學(xué)', '生物']
    },
    {
      title: '星期三',
      projects: ['歷史', '地理', '政治']
    },
    {
      title: '星期四',
      projects: ['美術(shù)', '音樂', '體育']
    }
  ]

  @Builder
  itemHead(text: string) {
    Text(text)
      .fontSize(20)
      .backgroundColor(0xAABBCC)
      .width("100%")
      .padding(10)
  }

  @Builder
  itemFoot(num: number) {
    Text('共' + num + "節(jié)課")
      .fontSize(16)
      .backgroundColor(0xAABBCC)
      .width("100%")
      .padding(5)
  }

  build() {
    Column() {
      List({ space: 20 }) {
        ForEach(this.timetable, (item: TimeTable) = > {
          ListItemGroup({ header: this.itemHead(item.title), footer: this.itemFoot(item.projects.length) }) {
            ForEach(item.projects, (project: string) = > {
              ListItem() {
                Text(project)
                  .width("100%")
                  .height(100)
                  .fontSize(20)
                  .textAlign(TextAlign.Center)
                  .backgroundColor(0xFFFFFF)
              }
            }, (item: string) = > item)
          }
          .divider({ strokeWidth: 1, color: Color.Blue }) // 每行之間的分界線
        })
      }
      .width('90%')
      .sticky(StickyStyle.Header | StickyStyle.Footer)
      .scrollBar(BarState.Off)
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  }
}

interface TimeTable {
  title: string;
  projects: string[];
}

zh-cn_image_0000001219864159

  • 示例2
// xxx.ets
@Entry
@Component
struct ListItemGroupExample2 {
  private arr: ArrObject[] = [
    {
      style: ListItemGroupStyle.CARD,
      itemStyles: [ListItemStyle.CARD, ListItemStyle.CARD, ListItemStyle.CARD]
    },
    {
      style: ListItemGroupStyle.CARD,
      itemStyles: [ListItemStyle.CARD, ListItemStyle.CARD, ListItemStyle.NONE]
    },
    {
      style: ListItemGroupStyle.CARD,
      itemStyles: [ListItemStyle.CARD, ListItemStyle.NONE, ListItemStyle.CARD]
    },
    {
      style: ListItemGroupStyle.NONE,
      itemStyles: [ListItemStyle.CARD, ListItemStyle.CARD, ListItemStyle.NONE]
    }
  ]

  build() {
    Column() {
      List({ space: "4vp", initialIndex: 0 }) {
        ForEach(this.arr, (item: ArrObject, index?: number) = > {
          ListItemGroup({ style: item.style }) {
            ForEach(item.itemStyles, (itemStyle: number, itemIndex?: number) = > {
              ListItem({ style: itemStyle }) {
                if (index != undefined && itemIndex != undefined) {
                  Text("第" + (index + 1) + "個(gè)Group中第" + (itemIndex + 1) + "個(gè)item")
                    .width("100%")
                    .textAlign(TextAlign.Center)
                }
              }
            }, (item: string) = > item)
          }
        })
      }
      .width('100%')
      .multiSelectable(true)
      .backgroundColor(0xDCDCDC) // 淺藍(lán)色的List
    }
    .width('100%')
    .padding({ top: 5 })
  }
}

interface ArrObject {
  style: number;
  itemStyles: number[];
}

ListItemGroupStyle

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • 組件
    +關(guān)注

    關(guān)注

    1

    文章

    498

    瀏覽量

    17771
  • 鴻蒙
    +關(guān)注

    關(guān)注

    57

    文章

    2287

    瀏覽量

    42629
收藏 人收藏

    評論

    相關(guān)推薦

    鴻蒙ArkTS容器組件:Column

    沿垂直方向布局的容器。
    的頭像 發(fā)表于 07-05 16:32 ?338次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:Column

    鴻蒙ArkTS容器組件:Flex

    以彈性方式布局子組件容器組件
    的頭像 發(fā)表于 07-08 10:19 ?340次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:Flex

    鴻蒙ArkTS容器組件:FlowItem

    [瀑布流組件]的子組件,用來展示瀑布流具體item。
    的頭像 發(fā)表于 07-08 09:56 ?268次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:FlowItem

    鴻蒙ArkTS容器組件:GridCol

    柵格子組件,必須作為柵格容器組件([GridRow])的子組件使用。
    的頭像 發(fā)表于 07-08 15:17 ?308次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:GridCol

    鴻蒙ArkTS容器組件:GridItem

    網(wǎng)格容器中單項(xiàng)內(nèi)容容器。
    的頭像 發(fā)表于 07-09 09:25 ?288次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:GridItem

    鴻蒙ArkTS容器組件:ListItem

    可以包含單個(gè)子組件
    的頭像 發(fā)表于 07-10 15:41 ?488次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:ListItem

    鴻蒙ArkTS容器組件:Navigator

    路由容器組件,提供路由跳轉(zhuǎn)能力。
    的頭像 發(fā)表于 07-10 14:55 ?317次閱讀

    鴻蒙ArkTS容器組件:Refresh

    可以進(jìn)行頁面下拉操作并顯示刷新動(dòng)效的容器組件。
    的頭像 發(fā)表于 07-11 16:11 ?363次閱讀

    鴻蒙ArkTS容器組件:RowSplit

    將子組件橫向布局,并在每個(gè)子組件之間插入一根縱向的分割線。
    的頭像 發(fā)表于 07-11 22:25 ?224次閱讀

    鴻蒙ArkTS容器組件:Scroll

    可滾動(dòng)的容器組件,當(dāng)子組件的布局尺寸超過父組件的尺寸時(shí),內(nèi)容可以滾動(dòng)。
    的頭像 發(fā)表于 07-12 15:24 ?927次閱讀

    鴻蒙ArkTS容器組件:SideBarContainer

    提供側(cè)邊欄可以顯示和隱藏的側(cè)邊欄容器,通過子組件定義側(cè)邊欄和內(nèi)容區(qū),第一個(gè)子組件表示側(cè)邊欄,第二個(gè)子組件表示內(nèi)容區(qū)。
    的頭像 發(fā)表于 07-18 15:46 ?381次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:SideBarContainer

    鴻蒙ArkTS容器組件:Stack

    堆疊容器,子組件按照順序依次入棧,后一個(gè)子組件覆蓋前一個(gè)子組件。
    的頭像 發(fā)表于 07-15 18:23 ?744次閱讀

    鴻蒙ArkTS容器組件:Swiper

    滑塊視圖容器,提供子組件滑動(dòng)輪播顯示的能力。
    的頭像 發(fā)表于 07-15 09:51 ?428次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:Swiper

    鴻蒙ArkTS容器組件:Tabs

    通過頁簽進(jìn)行內(nèi)容視圖切換的容器組件,每個(gè)頁簽對應(yīng)一個(gè)內(nèi)容視圖。
    的頭像 發(fā)表于 07-15 09:48 ?567次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:Tabs

    鴻蒙ArkTS容器組件:WaterFlow

    瀑布流容器,由“行”和“列”分割的單元格所組成,通過容器自身的排列規(guī)則,將不同大小的“項(xiàng)目”自上而下,如瀑布般緊密布局。
    的頭像 發(fā)表于 07-15 17:35 ?340次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:WaterFlow