参考demo:@Entry @Component struct NestedScroll { @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] private scrollerForScroll: Scroller = new Scroller() private scrollerForList: Scroller = new Scroller() build() { Flex() { Scroll(this.scrollerForScroll) { Column() { List({ space: 20, scroller: this.scrollerForList }) { ForEach(this.arr, (item: number) => { ListItem() { Text("ListItem" + item) .width("100%") .height("100%") .borderRadius(15) .fontSize(16) .textAlign(TextAlign.Center) .backgroundColor(Color.White) }.width("100%").height(100) }, (item: string) => item) } .width("100%") .height("50%") .edgeEffect(EdgeEffect.None) .friction(0.6) .onReachStart(() => { this.listPosition = 0 }) .onReachEnd(() => { this.listPosition = 2 }) .onScrollFrameBegin((offset: number) => { if ((this.listPosition == 0 && offset <= 0) || (this.listPosition == 2 && offset >= 0)) { this.scrollerForScroll.scrollBy(0, offset) return { offsetRemain: 0 } } this.listPosition = 1 return { offsetRemain: offset }; }) AreaTest() } } .width("100%").height("100%") }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20) } } @Component struct AreaTest { build() { Text("Scroll Area") .width("100%") .height("40%") .backgroundColor(0X330000FF) .fontSize(16) .textAlign(TextAlign.Center) .margin(90) } }
参考demo: