这个是tabs高度未确定,定高即可,参考代码段Tabs({ barPosition: BarPosition.Start }) { // TabContent的内容:关注、视频、游戏、数码、科技、体育、影视 ... } 参考链接https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-navigation-tabs-0000001820999773\#ZH-CN\_TOPIC\_0000001820999773\_\_%E9%A1%B6%E9%83%A8%E5%AF%BC%E8%88%AA@Entry @Component struct TabsExample11 { @State tabArray: Array<number> = [0, 1,2] @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) { Row({ space: 20 }) { Text(tabName).fontSize(18) .fontColor(tabItem===this.focusIndex?Color.Red:Color.Black) } .justifyContent(FlexAlign.Center) .constraintSize({ minWidth: 35 }) .width(80) .height(60) .borderRadius({ topLeft: 10, topRight: 10 }) .onClick(() => { this.controller.changeIndex(tabIndex) this.focusIndex = tabIndex }) } build() { Column() { Column() { // 页签 Row({ space: 7 }) { 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('90%') } .alignItems(VerticalAlign.Bottom) .width('100%') } .alignItems(HorizontalAlign.Start) .width('100%') //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.Pink) }) } .width('100%') .barHeight(0) .animationDuration(100) .onChange((index: number) => { console.log('foo change') this.focusIndex = index}) } .height('100%') } }需要tabbar靠左的话 建议可以通过自定义tabbar来实现可以参考以上demo解决
这个是tabs高度未确定,定高即可,参考代码段
参考链接https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-navigation-tabs-0000001820999773\#ZH-CN\_TOPIC\_0000001820999773\_\_%E9%A1%B6%E9%83%A8%E5%AF%BC%E8%88%AA
需要tabbar靠左的话 建议可以通过自定义tabbar来实现可以参考以上demo解决