HarmonyOS 是否有可吸顶的tab滑动组件呢?

是否有支持滑动到一段距离,tab吸顶的组件呢?

HarmonyOS
2024-12-26 15:52:01
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

参考:

@Entry
@Component
struct Index_231204142752067 {
  @State height1: number = 30
  build() {
    Stack() {
      // 主内容
      Scroll() {
        Column() {
          ScrollHeaderArea()
            .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => {
              if (!isVisible) {
                this.height1 = 50
              } else {
                this.height1 = 30
              }
            })
          // 主内容
          ScrollMainArea({ height1: this.height1 })
        }.width("100%")
      }
      .edgeEffect(EdgeEffect.None)
      .friction(0.6)
      .backgroundColor('#DCDCDC')
      .scrollBar(BarState.Off)
      .width('100%')
      .height('100%')
      // 头部右上角图标
      header()
    }
  }
}

@Component
struct header {
  build() {
    Row() {
      Blank().layoutWeight(1)
      Row() {
        Image($r('app.media.startIcon'))
          .width(20)
          .height(20)
          .margin({ right: 10 })
          .onClick(() => {
            console.log('11111')
          })
        Image($r('app.media.startIcon'))
          .width(20)
          .height(20).onClick(() => {
          console.log('111112')
        })
      }.margin({ right: 10 })
    }.width('100%').position({ y: 10 })
  }
}

@Component
struct ScrollHeaderArea {
  build() {
    Row() {
      Row() {
        Text('1').fontSize(20).layoutWeight(1)
        Text('1').fontSize(20).layoutWeight(1)
        Text('1').fontSize(20).layoutWeight(1)
        Text('1').fontSize(20).layoutWeight(1)
      }
      .backgroundColor(Color.White)
      .margin(10)
      .borderRadius(5)
      .height(50)

    }.backgroundColor(Color.Pink)
    .padding({ top: 50, bottom: 50 })
  }
}
@Component
struct ScrollMainArea {
  @State arr: number[] = [1, 2, 3, 4, 5, 6]
  @Prop height1: number

  @Builder
  headerItem() {
    Column() {
      Text()
        .size({ width: '100%', height: this.height1 })
        .animation({
          duration: 300
        })
        .backgroundColor(Color.Red)
        .fontSize(16)
        .align(Alignment.Start)
        .position({ x: 0, y: 0 })
      Image($r('app.media.icon')).width(40).height(40).padding({ left: 5 })
    }
  }

  @Styles
  listCard() {
    .backgroundColor(Color.White)
    .height(200)
    .width("100%")
    .borderRadius(12)
  }

  build() {
    Column() {
      List({ space: 10 }) {
        ListItemGroup({ header: this.headerItem }) {
          ForEach(this.arr, (item: number) => {
            ListItem() {
              Text("item" + item)
                .fontSize(16)
            }.listCard()
          }, (item: string) => item)
        }
      }
      .sticky(StickyStyle.Header)
      .width("100%")
      .height('100%')
      .edgeEffect(EdgeEffect.None)
      .nestedScroll({
        scrollForward: NestedScrollMode.PARENT_FIRST,
        scrollBackward: NestedScrollMode.SELF_FIRST
      })
    }.width('100%').height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-26 18:20:44
相关问题
HarmonyOS 折叠
238浏览 • 1回复 待解决
如何实现分组列表/底效果
2507浏览 • 1回复 待解决
HarmonyOS 如何实现交互实现-
675浏览 • 1回复 待解决
页面和列表嵌套滚动,实现列表
1722浏览 • 1回复 待解决
HarmonyOS 是否滑动验证弹窗组件
645浏览 • 1回复 待解决
HarmonyOS 是否自带顶效果UI控件
194浏览 • 1回复 待解决