鸿蒙开发:案例集合Tabs:tabs竖向粘性

🎯 案例集合Tabs:tabs竖向粘性

🌍 案例集合Tabs

🚪 最近开启了学员班级点我欢迎加入

🏷️ 效果图

📖 参考

🧩 拆解

  • 自定义tabs突出球 左右滑动
javascript 复制代码
/**
 * tab模拟数据
 */
const tabsMockData: string[] = ['购物', '体育', '服装', '军事']
/**
 * TabContents模拟数据
 */
const tabContentsMockData: number[] = [1, 2, 3, 4, 5]

@Component
export struct TabsStickyCase {

  /**
   * 标签内容
   */
  @Builder
  tabContentsBuilder() {
    List({ space: 20 }) {
      ForEach(tabContentsMockData, (item: number) => {
        ListItem() {
          Text(item.toString())
            .height(200)
            .width('100%')
            .borderRadius(10)
            .textAlign(TextAlign.Center)
            .borderWidth(1)
            .borderColor(Color.Gray)
        }
      })
    }
    .width('100%')
    .height('100%')
    .padding(10)
    .scrollBar(BarState.Off) // 关闭滚动条
    .edgeEffect(EdgeEffect.None) // 关闭边缘效果
    // 关键:
    .nestedScroll({
      scrollForward: NestedScrollMode.PARENT_FIRST, // 滚动组件往末尾端滚动时:父组件先滚动
      scrollBackward: NestedScrollMode.SELF_FIRST // 滚动组件往起始端滚动时:自身先滚动,自身滚动到边缘以后父组件滚动。
    })
  }

  /**
   * 模拟Swipe组件或者banner组件
   */
  @Builder
  mockSwipeBuilder() {
    Stack({ alignContent: Alignment.Center }) {
      Image($r('app.media.startIcon'))
        .width('100%')
        .height(200)
        .draggable(false)
        .borderRadius(10)
      Text('模拟Swipe组件')
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
    }
    .height(200)
    .width('100%')
  }

  build() {
    Column() {
      Scroll() {
        Column() {
          this.mockSwipeBuilder()

          // 标签导航
          Tabs() {
            ForEach(tabsMockData, (item: string) => {
              TabContent() {
                this.tabContentsBuilder()
              }
              .tabBar(SubTabBarStyle.of(item)
                .indicator({ width: 72, marginTop: 13, color: Color.Orange })
                .board({ borderRadius: 0 })
                .labelStyle({ selectedColor: Color.Orange, font: { size: 16 } })
              )
            })
          }
          .barHeight(50)

        }
      }
      .layoutWeight(1)
      .scrollBar(BarState.Off) // 关闭滚动条
      .edgeEffect(EdgeEffect.None) // 关闭边缘效果
    }
    .size({ height: '100%', width: '100%' })
  }
}

🌸🌼🌺

相关推荐
大锅盖127 分钟前
围绕夜航深蓝与霓虹青的跨境画卷构建 HarmonyOS ArkUI 出境旅行向导平台
华为·harmonyos
骐骥19 小时前
学习:使用postMessage()建立应用侧与前端页面的数据通道
harmonyos·鸿蒙·jsbridge·postmessage·数据通道
HwJack2016 小时前
鸿蒙开发ArkData 全景与选型决策:三种存储到底用哪个
华为·harmonyos
czhm5716 小时前
基于 HarmonyOS ArkTS API 24,工具函数抽离业务计算逻辑,状态颜色判断解耦组件代码
harmonyos·arkts
lilian23317 小时前
HarmonyOS 7 新特性(九)|碰一碰精准分享与互动卡片
华为·harmonyos
lilian23317 小时前
HarmonyOS 7 新特性(十)|DevEco Code 与 DevEco CLI AI 开发提效
人工智能·华为·harmonyos
袁震18 小时前
HarmonyOS 应用包体积优化与上架自检实战:从 76.2MB 到 3.6MB
java·华为·性能优化·harmonyos
2501_9197490319 小时前
华为鸿蒙免费美食APP—小羊美食
华为·harmonyos·美食
czhm5721 小时前
HarmonyOS 6.1 实战:长列表 ForEach 性能优化,大数据量列表避免不必要的组件重渲染
华为·harmonyos
lilian23321 小时前
HarmonyOS 7 新特性(七)|JsLeakWatcher 与 HWASan 内存治理
华为·harmonyos