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)單獨標(biāo)記該內(nèi)容的起始版本。
- 該組件的父組件只能是[List]
使用說明
當(dāng)ListItemGroup的父組件List的listDirection屬性為Axis.Vertical時,不允許設(shè)置ListItemGroup組件的height屬性。ListItemGroup的高度為header高度、footer高度和所有ListItem布局后總高度之和。當(dāng)父組件List的listDirection屬性為Axis.Horizontal時,不允許設(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ù)描述 |
---|---|---|---|
header | [CustomBuilder] | 否 | 設(shè)置ListItemGroup頭部組件。 |
footer | [CustomBuilder] | 否 | 設(shè)置ListItemGroup尾部組件。 |
space | number | string | 否 |
style10+ | [ListItemGroupStyle] | 否 | 設(shè)置List組件卡片樣式。 默認(rèn)值: ListItemGroupStyle.NONE 設(shè)置為ListItemGroupStyle.NONE時無樣式。 設(shè)置為ListItemStyle.CARD時,必須配合[ListItem]的ListItemStyle.CARD同時使用,顯示默認(rèn)卡片樣式。 卡片樣式下, 為卡片內(nèi)的列表選項提供了默認(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ù)類型 | 描述 |
---|---|---|
divider | { strokeWidth: [Length], color?: [ResourceColor], startMargin?: [Length], endMargin?: [Length] } | null |
ListItemGroupStyle10+枚舉說明
名稱 | 描述 |
---|---|
NONE | 無樣式。 |
CARD | 顯示默認(rèn)卡片樣式。 |
說明:
ListItemGroup組件不支持設(shè)置[通用屬性aspectRatio]。
ListItemGroup組件如果主軸方向是垂直方向時,設(shè)置[通用屬性height]屬性不生效。
HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
ListItemGroup組件如果主軸方向是水平方向時,設(shè)置[通用屬性width]屬性不生效。
示例
// 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[];
}
- 示例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) // 淺藍(lán)色的List
}
.width('100%')
.padding({ top: 5 })
}
}
interface ArrObject {
style: number;
itemStyles: number[];
}
審核編輯 黃宇
-
組件
+關(guān)注
關(guān)注
1文章
518瀏覽量
17938 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2395瀏覽量
43091
發(fā)布評論請先 登錄
相關(guān)推薦
鴻蒙ArkTS容器組件:SideBarContainer
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:SideBarContainer](https://file1.elecfans.com/web2/M00/EB/95/wKgZomZevfiAZTUiAAAYyNC3ogI340.png)
評論