HarmonyOS Tabs组件Scrollable模式下tabBar怎么让它从上往下依次排列?

Tabs组件Scrollable模式下我看API是只支持tabBar平均分布,或者排在中间,怎么让它从上往下依次排列呢

阅读 450
1 个回答

请参考以下示例:

@Entry
@Component
struct TabCheck {
  @State tabArray: Array<number> = [0, 1, 3, 4 ]
  @State focusIndex: number = 0
  @State pre: number = 0
  @State index: number = 0
  private controller: TabsController = new TabsController()
  @State test: boolean = false
  // 单独的页签
  @Builder
  Tab(tabName: string, tabItem: number, tabIndex: number) {
    Column({ space: 20 }) {
      Text(tabName)
        .fontSize(22)
        .fontColor(tabIndex === this.focusIndex ? "#0000FF " : "#000000")
        .margin({top: '17%'})
    }
    .width(60)
    .height(60)
    .onClick(() => {
      this.controller.changeIndex(tabIndex)
      this.focusIndex = tabIndex
    })
  }
  build() {
    Column() {
      Row() {
        // 页签
        Column({ space: 7 }) {
          Scroll() {
            Column() {
              ForEach(this.tabArray, (item: number, index: number) => {
                this.Tab("签页" + item, item, index)
              })
            }
            .height('100%')
          }
          .align(Alignment.Start)
          .scrollable(ScrollDirection.Horizontal)
          .scrollBar(BarState.Off)
          .height('100%')
          .backgroundColor(Color.Pink)
        }
        .height('100%')
        .backgroundColor(Color.Pink)
        .justifyContent(FlexAlign.Start)
        //tabs
        Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
          ForEach(this.tabArray, (item: number, index: number) => {
            TabContent() {
              Text('我是页面 ' + item + " 的内容")
                .height(300)
                .width('100%')
                .fontSize(30)
            }
            .backgroundColor(Color.Gray)
          })
        }
        .barHeight(0)
        .animationDuration(100)
        .onChange((index: number) => {
          console.log('foo change')
          this.focusIndex = index
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进