可以使用替代方案在List外面要嵌套Row组件,不要直接把List做根组件。示例参考如下:@Entry @Component struct ListLanesExample { @State arr: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8",] @State alignListItem: ListItemAlign = ListItemAlign.Center build() { Row() { List({ space: 8 }) { ForEach(this.arr, (item: string) => { ListItem() { Text('' + item) .width(80) .height(30) .fontSize(16) .textAlign(TextAlign.Center) .borderRadius(10) .backgroundColor(0xFFFFFF) } .border({ width: 2, color: Color.Green }) }, (item: string) => item) } .height('100%') .layoutWeight(1) .listDirection(Axis.Horizontal) .border({ width: 3, color: Color.Red }) .alignListItem(this.alignListItem) .scrollBar(BarState.Off) .contentStartOffset(20) } .height(64) } }
可以使用替代方案在List外面要嵌套Row组件,不要直接把List做根组件。示例参考如下: