HarmonyOS tabBar中无法显示全,如何适配?

tabBar的设置值有:

‘推荐’,

‘少儿’,

‘成人’,

‘父母’,

‘财富保险’,

‘家庭’,

‘旅行’,

目前的显示情况为:财富保险这个无法正常展示全,要如何调整?

期望效果:

阅读 438
1 个回答

请参考以下实现方式:

@Entry
@Component
struct TabsBarWidgets {
  @State tabArray: Array<string> = ['推荐', '少儿','成人','父母','财富保险','家庭','旅行','社会']
  @State focusIndex: number = 0
  @State pre: number = 0
  @State index: number = 0
  private controller: TabsController = new TabsController()
  private scroller: Scroller = new Scroller()
  @State test: boolean = false
  // 单独的页签
  @Builder Tab(tabName: string, tabItem: number, tabIndex: number) {
    Flex({direction:FlexDirection.Column,justifyContent:FlexAlign.SpaceAround,alignItems:ItemAlign.Center}) {
      Text(tabName).fontSize(18)
        .fontColor(tabIndex === this.focusIndex ?Color.Blue: Color.Black)
      Divider()
        .backgroundColor(tabIndex === this.focusIndex ?Color.Blue: Color.White)
        .height(3)
        .width(tabIndex === this.focusIndex ?(90/this.tabArray.length*0.4).toString()+'%':0.01)

    }

    .constraintSize({ minWidth: 35 })
    .height(40)
    .backgroundColor(Color.Orange)
    .onClick(() => {
      this.controller.changeIndex(tabIndex)
      this.focusIndex = tabIndex
    })
  }
  build() {
    Column() {
      Column() {
        // 页签
        Row() {
          ForEach(this.tabArray, (item: string, index: number) => {
            this.Tab( item, index, index)

          })
        }
        .justifyContent(FlexAlign.SpaceAround)
        .width('100%')
        Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
          ForEach(this.tabArray, (item: number, index: number) => {
            TabContent() {
              Text('页面' + item )
                .height(300)
                .width('100%')
                .fontSize(30)
            }
          })
        }
        .barHeight(0)
        .animationDuration(100)
        .onChange((index: number) => {
          console.log('foo change')
          this.focusIndex = index
          this.scroller.scrollTo({xOffset: 120*index,yOffset:0})
        })
      }
      .alignItems(HorizontalAlign.Start)
      .width('100%')
    }
    .height('100%')

  }
}