可以设置maxcount属性看看@Entry @Component struct CalcGridHeight { build() { Column() { Text('一段文字') Grid() { ForEach([1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 1, 1, 1, 1, 1, 1, 1], (item: number, index: number) => { GridItem() { Column() { Text(item.toString()) .width('100%') .backgroundColor('#ccc') if (index === 0) { Text('test').height(30) } } } .width('20%') .padding(12) }) }.maxCount(5) Text('一段文字') }.height('100%') .width('100%') } }
可以设置maxcount属性看看