具体可参考以下demo实现:@Entry @Component struct ListExample { private arr: number[] = [] private scrollerForList: Scroller = new Scroller() aboutToAppear() { for (let i = 0; i < 20; i++) { this.arr.push(i) } } build() { Column() { Row() { List({ space: 10, initialIndex: 0, scroller: this.scrollerForList }) { ForEach(this.arr, (item: number) => { ListItem() { Text('' + item) .width('100%').height(50).fontSize(16) .textAlign(TextAlign.Center) } .borderRadius(10).backgroundColor(0xFFFFFF) }, (item: number) => JSON.stringify(item)) } .chainAnimation(true) .borderRadius(10) .backgroundColor(0xDCDCDC) } .width('100%') .height(300) .backgroundColor(0xDCDCDC) Button() { Text('scrollToIndex (0)') }.onClick(()=>{ this.scrollerForList.scrollToIndex(0,true) }).height('10%').width('60%') Button() { Text('scrollToIndex (19)') }.onClick(()=>{ this.scrollerForList.scrollToIndex(19,true) }).height('10%').width('60%') } } }
具体可参考以下demo实现: