鸿蒙实现滚动吸顶效果

废话不多说直接上代码,控制吸顶的属性.nestedScroll({

  scrollForward: NestedScrollMode.PARENT_FIRST,

  scrollBackward: NestedScrollMode.SELF_FIRST

})

@Entry

@Component

struct Index {

  @State list: number[] = []

  private indexNo: number =  0

  aboutToAppear() {//添加测试数据

    for (let i = 0; i < 15; i++) {

      this.list.push(i)

    }

}

  @Styles

  listStyle() {

    .backgroundColor(Color.White)

    .height(72)

    .width("100%")

    .borderRadius(12)

  }

  @Builder

  TabBuilder(title: string,index:number) {

    Column() {

      Text(title)

        .fontSize(20)

        .fontColor(Color.White)

    }

    .padding({ top: 10, bottom: 10 })

    .justifyContent(FlexAlign.Center)

    .backgroundColor(Color.Pink)

    .height(56)

    .width('100%')

  }

  @Builder

  tabBuilder() {

    Tabs() {

      ForEach(this.list, (item: number,Index:number) => {

        TabContent() {

          List({ space: 10 }) {

            ForEach(this.list, (subItem: number,index:number) => {

              ListItem() {

                Text("item" + subItem).fontSize(16)

              }.listStyle()

            }, (subItem: string) => subItem)

          }.width("100%")

          .height('100%')

          .edgeEffect(EdgeEffect.None)

          .nestedScroll({

            scrollForward: NestedScrollMode.PARENT_FIRST,

            scrollBackward: NestedScrollMode.SELF_FIRST

          })

        }.tabBar(this.TabBuilder("Tab " + item, Index))

      }, (item: number) => item.toString())

    }

}

  build() {

    Scroll() {

      Column() {

        Text("头部滚动区域")

          .width("100%")

          .height("30%")

          .fontSize(20)

          .fontColor(Color.White)

          .backgroundColor('#0080DC')

          .textAlign(TextAlign.Center)

        Tabs() {

          TabContent() {

            //滑动布局

            this.tabBuilder()

          }

          .tabBar() //吸顶布局

        }

        .barHeight(0)

        .vertical(false)

        .height("100%")

      }.width("100%")

    }

    .edgeEffect(EdgeEffect.None)

    .backgroundColor('#DCDCDC')

    .scrollBar(BarState.Off)

    .width('100%')

    .height('100%')

  }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容