HarmonyOS tabs中的tabbar整体位置调整

tabs中的tabbar整体可以不居中,而是从顶部开始排序么,超出可以滑动。官方api只看到了三种模式ALWAYS_CENTER,ALWAYS_AVERAGE_SPLIT,SPACE_BETWEEN_OR_CENTER均不能满足。

HarmonyOS
2024-12-25 13:06:53
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
aquaa

参考示例:

@Extend(Text)
function tabBarStyle(isHigt: boolean) {
  .width("100%")
  .textAlign(TextAlign.Center)
  .backgroundColor(isHigt ? Color.Gray : Color.Transparent)
  .height(40)
}

@Entry
@Component
struct GridPage {
  @State currentIndex: number = 0

  build() {
    Row() {
      Column() {
        Row() {
          // 页签
          Column({ space: 16 }) {
            Text("pink")
              .tabBarStyle(this.currentIndex == 0)
              .onClick(() => {
                this.currentIndex = 0
              })
            Text("yellow")
              .tabBarStyle(this.currentIndex == 1)
              .onClick(() => {
                this.currentIndex = 1
              })
            Text("blue")
              .tabBarStyle(this.currentIndex == 2)
              .onClick(() => {
                this.currentIndex = 2
              })
            Text("green")
              .tabBarStyle(this.currentIndex == 3)
              .onClick(() => {
                this.currentIndex = 3
              })
            Text("red")
              .tabBarStyle(this.currentIndex == 4)
              .onClick(() => {
                this.currentIndex = 4
              })
          }
          .justifyContent(FlexAlign.Start)
          .height("100%")
          .width("60")

          Tabs({ index: this.currentIndex }) {
            TabContent() {
              Column().width('100%').height('100%').backgroundColor(Color.Pink)
            }

            TabContent() {
              Column().width('100%').height('100%').backgroundColor(Color.Yellow)
            }

            TabContent() {
              Column().width('100%').height('100%').backgroundColor(Color.Blue)
            }

            TabContent() {
              Column().width('100%').height('100%').backgroundColor(Color.Green)
            }

            TabContent() {
              Column().width('100%').height('100%').backgroundColor(Color.Red)
            }
          }
          .barWidth(0)
          .vertical(true)
          .scrollable(true)
          .margin({ bottom: '12vp' })
        }
      }
      .width('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-25 15:55:54
相关问题
HarmonyOS Tabs组件TabBar不能完全贴合
221浏览 • 1回复 待解决
如何在TabstabBar,添加其他组件
939浏览 • 1回复 待解决
HarmonyOS Tabs组件tabBar宽度问题
855浏览 • 1回复 待解决
HarmonyOS tabstabBar怎么居左
671浏览 • 1回复 待解决
HarmonyOS Tabs 组件无法隐藏 tabbar
222浏览 • 1回复 待解决
HarmonyOS 如何设定tabs组件tabbar样式
796浏览 • 1回复 待解决
HarmonyOS Tabs位置问题
69浏览 • 1回复 待解决
HarmonyOS怎么调整Radio选项框位置
536浏览 • 1回复 待解决
Scroll子组件展示位置如何调整
2710浏览 • 1回复 待解决
关于Tabs里面tabBar样式问题
554浏览 • 2回复 待解决
鸿蒙如何调整组件位置
7778浏览 • 1回复 待解决
HarmonyOS Tabs组件tabBar是否可以居左
169浏览 • 1回复 待解决