HarmonyOS 如何实现类似与coordinatelayout的那种tab吸顶的效果?

HarmonyOS 如何实现类似与coordinatelayout的那种tab吸顶的效果?

HarmonyOS
2024-10-21 10:05:41
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

demo如下:

@Entry  
@Component  
struct listDemo {  
  @State topHeight: number = -1  
  @State topMargin: number = 0  
  isFirst: boolean = true;  
  startTop: number = 0;  
  
  build() {  
    Stack({ alignContent: Alignment.Top }) {  
      // 主内容  
      Scroll() {  
        Column() {  
          ScrollHeaderArea()  
            .onAreaChange((oldArea: Area, newArea: Area) => {  
              if (this.isFirst) {  
                this.isFirst = false;  
                this.startTop = Number(newArea.globalPosition.y)  
              }  
              if (this.startTop - Number(newArea.globalPosition.y) + this.topHeight >= Number(newArea.height)) {  
                console.log("cbl:::----------------------------------------")  
                console.log("cbl:::", this.topHeight)  
                console.log("cbl:::", JSON.stringify(newArea))  
                console.log("cbl:::", this.startTop)  
                console.log("cbl:::", Number(newArea.height))  
                console.log("cbl:::", Number(newArea.globalPosition.y))  
                if (this.topMargin <= 50) {  
                  if (this.startTop - Number(newArea.globalPosition.y) + this.topHeight - Number(newArea.height) >= 50) {  
                    this.topMargin = 50  
                  } else {  
                    this.topMargin = this.startTop - Number(newArea.globalPosition.y) + this.topHeight - Number(newArea.height)  
                  }  
                }  
              } else {  
                this.topMargin = 0  
              }  
            })  
          // 主内容  
          ScrollMainArea({ topMargin: this.topMargin })  
        }.width("100%")  
      }  
      .edgeEffect(EdgeEffect.None)  
      .friction(0.6)  
      .backgroundColor(Color.Grey)  
      .scrollBar(BarState.Off)  
      .width('100%')  
      .height('100%')  
  
      // 头部输入框  
      header()  
        .onAreaChange((oldArea: Area, newArea: Area) => {  
          this.topHeight = Number(newArea.height)  
        })  
    }.height("100%")  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
分享
微博
QQ
微信
回复
2024-10-21 15:56:08
相关问题
如何实现分组列表/效果
2840浏览 • 1回复 待解决
HarmonyOS 如何实现交互实现-
907浏览 • 1回复 待解决
HarmonyOS里怎么实现CoordinateLayout效果
1207浏览 • 1回复 待解决
HarmonyOS 折叠
472浏览 • 1回复 待解决
如何实现通用效果
1164浏览 • 1回复 待解决
页面和列表嵌套滚动,实现列表
2174浏览 • 1回复 待解决
HarmonyOS 如何实现顶部效果
485浏览 • 1回复 待解决
如何实现Tabs组件tarbar效果
2126浏览 • 1回复 待解决
HarmonyOS 如何实现折叠效果
637浏览 • 1回复 待解决
如何实现类似keyframes效果
2347浏览 • 1回复 待解决
tabs结合scroll实现效果
2355浏览 • 1回复 待解决
HarmonyOS 如何实现类似match_parent效果
1093浏览 • 1回复 待解决