鸿蒙tab左对齐

@Component
export struct expenditure {
@State focusIndex: number = 0;
private controller: TabsController = new TabsController();
tabArray = [‘全部’, ‘获得’,‘消费’];

// 自定义页签
@Builder
Tab(tabName: string, tabItem: number, tabIndex: number) {
Column({ space: 20 }) {
Text(tabName).fontSize(18)
}.alignItems(HorizontalAlign.Center)
.width(60)
.height(25)
.onClick(() => {
this.controller.changeIndex(tabIndex);
this.focusIndex = tabIndex;
})
.backgroundColor(tabIndex === this.focusIndex ? ‘#ffb7b7b7’:‘#ffffffff’)
}

build() {
Column() {
Column() {
// 页签
Row({ space: 6 }) {
Scroll() {
Row() {
ForEach(this.tabArray, (item: number, index: number) => {
this.Tab(‘’ + item, item, index);
})
}
.justifyContent(FlexAlign.Start)
}
// 设置左对齐
.align(Alignment.Start)
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
.width(‘80%’)

    }
    .width('100%')
    // .backgroundColor('#ffb7b7b7')

    // tabs
    Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
      ForEach(this.tabArray, (item: number, index: number) => {
        TabContent() {
        if(index==0){
          Text('1')
        }else if(index==1){
          Text('2')
        }else if(index==2){
          Text('3')
        }
        }
      })
    }
    .barHeight(0)
    .animationDuration(100)
    .onChange((index: number) => {
      console.log('foo change');
      this.focusIndex = index;
    })
  }
  .alignItems(HorizontalAlign.Start)
  .width('100%')
}
.height('100%')

}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值