参考demo:@Entry @Component struct ListDragTest { @State arr: string[] = []; private leftListScroller: ListScroller = new ListScroller() private rightListScroller: ListScroller = new ListScroller() aboutToAppear() { for (let i = 1; i <= 15; i++) { this.arr.push("item_" + i); } } @Builder textItem(content: string) { Text(content) .width('100%') .height(150) .textAlign(TextAlign.Center) } build() { Row() { List({ space: 10, scroller: this.leftListScroller }) { ForEach(this.arr, (item: string) => { ListItem() { this.textItem(item) } }) } .onScrollFrameBegin((offset: number, state: ScrollState) => { this.rightListScroller.scrollBy(0, offset) return {offsetRemain: offset} }) .layoutWeight(1) .height('100%') List({ space: 10, scroller: this.rightListScroller }) { ForEach(this.arr, (item: string) => { ListItem() { this.textItem(item) } }) } .onScrollFrameBegin((offset: number, state: ScrollState) => { this.leftListScroller.scrollBy(0, offset) return {offsetRemain: offset} }) .layoutWeight(1) .height('100%') }.width('100%').margin({ top: 5 }) } }
参考demo: