HarmonyOS scroll嵌套多个list后scroll滑动没反应?

尝试了在list中设置

.nestedScroll({
  scrollForward: NestedScrollMode.PARENT_FIRST,
  scrollBackward: NestedScrollMode.SELF_FIRST
})

也没有效果

想要禁用掉list的滑动,只保留scroll的滑动

阅读 473
1 个回答

scroll嵌套多个list实现请参考如下demo

class itemType {
  id: number = -1
  typeName: string = ''
}
let listData: Array<object> = [
  {
    id: 1,
    typeName: 'ikf-min4',
  } as itemType,
  {
    id: 2,
    typeName: 'ikf-Find Air-4'
  } as itemType,
  {
    id: 3,
    typeName: 'ikf-Sky'
  } as itemType,
  {
    id: 4,
    typeName: 'ikf-Find Air-5'
  } as itemType,
  {
    id: 5,
    typeName: 'ikf-Zeus'
  } as itemType,
  {
    id: 6,
    typeName: 'ikf-Fly'
  } as itemType,
  {
    id: 7,
    typeName: 'ikf-min4',
  } as itemType,
  {
    id: 8,
    typeName: 'ikf-Find Air-4'
  } as itemType,
  {
    id: 9,
    typeName: 'ikf-Sky'
  } as itemType,
  {
    id: 10,
    typeName: 'ikf-Find Air-5'
  } as itemType,
  {
    id: 11,
    typeName: 'ikf-Zeus'
  } as itemType,
  {
    id: 12,
    typeName: 'ikf-Fly'
  } as itemType,
  {
    id: 13,
    typeName: 'ikf-Find Air-6'
  } as itemType,
  {
    id: 14,
    typeName: 'ikf-Zeus-1'
  } as itemType,
  {
    id: 15,
    typeName: 'ikf-Fly-3'
  } as itemType,
];
@Component
@Entry struct EarphoneType {
  scroller: Scroller = new Scroller()
  @Builder
  itemBuilder(item:itemType) {
    Row() {
      Text(item.typeName)
        .fontSize(16)
        .fontColor('#333')
    }
    .width('100%')
    .padding(20)
    .justifyContent(FlexAlign.SpaceBetween)
  }
  aboutToAppear(): void {
  }
  build() {
    Column() {
      Scroll(this.scroller) {
        Column() {
          List() {
            ForEach(listData, (item: itemType) => {
              ListItem() {
                this.itemBuilder(item)
              }
            }, (item: itemType) => JSON.stringify(item))
          }
          .backgroundColor('#fff')
          .borderRadius(10)
          .margin({bottom: 20})
          List() {
            ForEach(listData, (item: itemType) => {
              ListItem() {
                this.itemBuilder(item)
              }
            }, (item: itemType) => JSON.stringify(item))
          }
          .backgroundColor('#fff')
          .borderRadius(10)
        }
      }
    }
    .height('100%')
    .padding({left: 15, right: 15, top: 15})
    .backgroundColor("#f7f7f7")
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进