0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

鸿蒙ArkTS容器组件:ListItemGroup

jf_46214456 来源:jf_46214456 作者:jf_46214456 2024-07-10 09:20 次阅读

ListItemGroup

该组件用来展示列表item分组,宽度默认充满[List]组件,必须配合List组件来使用。

说明:
开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

  • 该组件从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
  • 该组件的父组件只能是[List]

使用说明

当ListItemGroup的父组件List的listDirection属性为Axis.Vertical时,不允许设置ListItemGroup组件的height属性。ListItemGroup的高度为header高度、footer高度和所有ListItem布局后总高度之和。当父组件List的listDirection属性为Axis.Horizontal时,不允许设置ListItemGroup组件的width属性。ListItemGroup的宽度为header宽度、footer宽度和所有ListItem布局后总宽度之和。

当前ListItemGroup内部的ListItem组件不支持编辑、拖拽功能,即ListItem组件的editable属性不生效。

子组件

包含[ListItem]子组件。

接口

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

参数

参数名参数类型必填参数描述
header[CustomBuilder]设置ListItemGroup头部组件。
footer[CustomBuilder]设置ListItemGroup尾部组件。
spacenumberstring
style10+[ListItemGroupStyle]设置List组件卡片样式。 默认值: ListItemGroupStyle.NONE 设置为ListItemGroupStyle.NONE时无样式。 设置为ListItemStyle.CARD时,必须配合[ListItem]的ListItemStyle.CARD同时使用,显示默认卡片样式。 卡片样式下, 为卡片内的列表选项提供了默认的focus、hover、press、selected和disable样式。**说明:**当前卡片模式下,不支持listDirection属性设置,使用默认Axis.Vertical排列方向。 当前卡片模式下,List属性alignListItem默认为ListItemAlign.Center,居中对齐显示。 当前卡片模式下,ListItemGroup不支持设置头部组件header和尾部组件footer。 若仅设置ListItemGroupStyle.CARD,未设置ListItemStyle.CARD时,只显示部分卡片样式及功能。

属性

名称参数类型描述
divider{ strokeWidth: [Length], color?: [ResourceColor], startMargin?: [Length], endMargin?: [Length] }null

ListItemGroupStyle10+枚举说明

名称描述
NONE无样式。
CARD显示默认卡片样式。

说明:

ListItemGroup组件不支持设置[通用属性aspectRatio]。

ListItemGroup组件如果主轴方向是垂直方向时,设置[通用属性height]属性不生效。
HarmonyOSOpenHarmony鸿蒙文档籽料:mau123789是v直接拿
ListItemGroup组件如果主轴方向是水平方向时,设置[通用属性width]属性不生效。

搜狗高速浏览器截图20240326151450.png

示例

// xxx.ets
@Entry
@Component
struct ListItemGroupExample {
  private timetable: TimeTable[] = [
    {
      title: '星期一',
      projects: ['语文', '数学', '英语']
    },
    {
      title: '星期二',
      projects: ['物理', '化学', '生物']
    },
    {
      title: '星期三',
      projects: ['历史', '地理', '政治']
    },
    {
      title: '星期四',
      projects: ['美术', '音乐', '体育']
    }
  ]

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

  @Builder
  itemFoot(num: number) {
    Text('共' + num + "节课")
      .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) + "个Group中第" + (itemIndex + 1) + "个item")
                    .width("100%")
                    .textAlign(TextAlign.Center)
                }
              }
            }, (item: string) = > item)
          }
        })
      }
      .width('100%')
      .multiSelectable(true)
      .backgroundColor(0xDCDCDC) // 浅蓝色的List
    }
    .width('100%')
    .padding({ top: 5 })
  }
}

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

ListItemGroupStyle

审核编辑 黄宇

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 组件
    +关注

    关注

    1

    文章

    495

    浏览量

    17722
  • 鸿蒙
    +关注

    关注

    56

    文章

    2266

    浏览量

    42468
收藏 人收藏

    评论

    相关推荐

    鸿蒙ArkTS容器组件:Column

    沿垂直方向布局的容器
    的头像 发表于 07-05 16:32 280次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:Column

    鸿蒙ArkTS容器组件:Flex

    以弹性方式布局子组件容器组件
    的头像 发表于 07-08 10:19 261次阅读
    <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。
    的头像 发表于 07-08 09:56 217次阅读
    <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])的子组件使用。
    的头像 发表于 07-08 15:17 248次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:GridCol

    鸿蒙ArkTS容器组件:GridItem

    网格容器中单项内容容器
    的头像 发表于 07-09 09:25 227次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:GridItem

    鸿蒙ArkTS容器组件:ListItem

    可以包含单个子组件
    的头像 发表于 07-10 15:41 408次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:ListItem

    鸿蒙ArkTS容器组件:Navigator

    路由容器组件,提供路由跳转能力。
    的头像 发表于 07-10 14:55 269次阅读

    鸿蒙ArkTS容器组件:Refresh

    可以进行页面下拉操作并显示刷新动效的容器组件
    的头像 发表于 07-11 16:11 285次阅读

    鸿蒙ArkTS容器组件:RowSplit

    将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。
    的头像 发表于 07-11 22:25 176次阅读

    鸿蒙ArkTS容器组件:Scroll

    可滚动的容器组件,当子组件的布局尺寸超过父组件的尺寸时,内容可以滚动。
    的头像 发表于 07-12 15:24 666次阅读

    鸿蒙ArkTS容器组件:SideBarContainer

    提供侧边栏可以显示和隐藏的侧边栏容器,通过子组件定义侧边栏和内容区,第一个子组件表示侧边栏,第二个子组件表示内容区。
    的头像 发表于 07-18 15:46 314次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:SideBarContainer

    鸿蒙ArkTS容器组件:Stack

    堆叠容器,子组件按照顺序依次入栈,后一个子组件覆盖前一个子组件
    的头像 发表于 07-15 18:23 656次阅读

    鸿蒙ArkTS容器组件:Swiper

    滑块视图容器,提供子组件滑动轮播显示的能力。
    的头像 发表于 07-15 09:51 320次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:Swiper

    鸿蒙ArkTS容器组件:Tabs

    通过页签进行内容视图切换的容器组件,每个页签对应一个内容视图。
    的头像 发表于 07-15 09:48 461次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:Tabs

    鸿蒙ArkTS容器组件:WaterFlow

    瀑布流容器,由“行”和“列”分割的单元格所组成,通过容器自身的排列规则,将不同大小的“项目”自上而下,如瀑布般紧密布局。
    的头像 发表于 07-15 17:35 295次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>组件</b>:WaterFlow