HarmonyOS tabs靠上排列?

如题:HarmonyOS tabs靠上排列?

阅读 559
1 个回答

示例:

@Entry
@Component
struct Tabbar_vertical {
  @State tabArray: Array<number> = [0, 1, 2]
  @State focusIndex: number = 0
  @State index: number = 0
  private controller: TabsController = new TabsController()


  @Builder Tab(tabName: string, tabItem: number, tabIndex: number) {
    Column() {
      Text(tabName).fontSize(18)
    }
    .width(100)
    .height(40)
    .onClick(() => {
      this.controller.changeIndex(tabIndex)
      this.focusIndex = tabIndex
    })
    .backgroundColor(tabIndex === this.focusIndex ? "#ffffffff" : "#ffb7b7b7")
    .justifyContent(FlexAlign.Center)
  }

  build() {
    Column() {
      Row() { //页签展示
        Column() {
          Scroll() {
            Column({ space: 10 }) {
              ForEach(this.tabArray, (item: number, index: number) => {
                this.Tab("页面" + item, item, index)
              })
            } //设置从顶部排列
            .justifyContent(FlexAlign.Start).height('100%')
          }
          .scrollable(ScrollDirection.Vertical)
        }
        .width('30%')
        .backgroundColor("#ffb7b7b7") //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('#ffbdf38d')
          })
        }
        .barHeight(0)
        .animationDuration(100)
        .onChange((index: number) => {
          console.log('foo change')
          this.focusIndex = index
        })
        .width('70%')
      }
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进