W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
該組件用來展示列表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屬性不生效。
ListItemGroup(options?: {header?: CustomBuilder, footer?: CustomBuilder, space?: number | string})
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
header | 否 | 設(shè)置ListItemGroup頭部組件。 | |
footer | 否 | 設(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屬性不生效。
- // xxx.ets
- @Entry
- @Component
- struct ListItemGroupExample {
- private timetable: any = [
- {
- 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) => {
- ListItemGroup({ header:this.itemHead(item.title), footer:this.itemFoot(item.projects.length) }) {
- ForEach(item.projects, (project) => {
- ListItem() {
- Text(project)
- .width("100%").height(100).fontSize(20)
- .textAlign(TextAlign.Center).backgroundColor(0xFFFFFF)
- }
- }, item => item)
- }
- .borderRadius(20)
- .divider({ strokeWidth: 1, color: Color.Blue }) // 每行之間的分界線
- })
- }
- .width('90%')
- .sticky(StickyStyle.Header|StickyStyle.Footer)
- }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: