HarmonyOS List页面如何主动停止滚动?

当用户在List页面上滚动时,点击某个按钮,如何让页面停止滚动

阅读 493
1 个回答

示例如下:

// xxx.ets
@Entry
@Component
struct DoubleList {
  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
  @State canScroll: boolean = true
  build() {
    Column() {
      List({ space: 20, initialIndex: 0 }) {
        ForEach(this.arr, (item: number) => {
          ListItem() {
            Text(`${item}`)
              .width('100%')
              .height(200)
              .fontSize(16)
              .textAlign(TextAlign.Center)
              .borderRadius(10)
              .backgroundColor(0xFFFFFF)
          }

          ListItem() {
            Button(`${item}`).onClick(() => {

            })
          }
        }, (item: string) => item)
      }
      .onClick(() => {
        console.log('click')
      })
      .enabled(this.canScroll)
      .onDidScroll((scrollState: ScrollState) => {
        console.log('scroll')
        this.canScroll = false;
      })
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0xDCDCDC)
    .padding({ top: 5 })
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进