中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
是否支持不同高度的TabContent在同一个TabBar中.
微信扫码分享
@Entry @Component struct Drag2 { @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 @State icon: string = 'app.media.icon' // @State marginBottom:number = 0 // 单独的页签 @Builder Tab(tabName: string, tabItem: number, tabIndex: number) { Row({ space: 10 }) { Text(tabName).fontSize(18) Stack() { // Column().width(tabIndex === this.focusIndex ? 50:25 ).height(tabIndex === this.focusIndex ? 50:25).borderRadius(25).backgroundColor(Color.Red) Image($r('app.media.local')) .width(tabIndex === this.focusIndex ? 40 : 20).height(tabIndex === this.focusIndex ? 40 : 20) } .margin({ bottom: tabIndex === this.focusIndex ? 20 : 0 }) } .justifyContent(FlexAlign.Center) .borderRadius({ topLeft: 10, topRight: 10 }) .onClick(() => { this.controller.changeIndex(tabIndex) this.focusIndex = tabIndex }) .backgroundColor(tabIndex === this.focusIndex ? "#ffefb2b2" : "#ffb7b7b7") .width(120) .height(50) } build() { Column() { Column() { // 页签 Row() { Scroll() { Row() { ForEach(this.tabArray, (item: number, index: number) => { this.Tab("页签 " + item, item, index) }) } .margin({ top: 20 }) .justifyContent(FlexAlign.SpaceBetween) } // .align(Alignment.Start) .scrollable(ScrollDirection.Horizontal) .scrollBar(BarState.Off) .width('100%') .backgroundColor("#ffb7b7b7") } .justifyContent(FlexAlign.SpaceBetween) .width('100%') .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(Color.Blue) }) } .barHeight(0) .animationDuration(100) .onChange((index: number) => { console.log('foo change') this.focusIndex = index }) } .alignItems(HorizontalAlign.Start) .width('100%') } .height('100%') } }