tabs组件不支持前后设置其他组件,也不支持前后tabs设置margin属性

tabs组件不支持前后设置其他组件,也不支持前后tabs设置margin属性。

HarmonyOS
2024-06-03 23:52:44
1.2w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
唯你而画

可以使用自定义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 
  // 单独的页签 
  @Builder 
  Tab(tabName: string, tabItem: number, tabIndex: number) { 
    Row({ space: 20 }) { 
      Text(tabName).fontSize(18) 
      Image($r('app.media.icon')).width(20).height(20) 
    } 
    .justifyContent(FlexAlign.Center) 
    .constraintSize({ minWidth: 35 }) 
    .width(100) 
    .height(30) 
    .borderRadius({ topLeft: 10, topRight: 10 }) 
    .onClick(() => { 
      this.controller.changeIndex(tabIndex) 
      this.focusIndex = tabIndex 
    }) 
    .backgroundColor(tabIndex === this.focusIndex ? "#ffffffff" : "#ffb7b7b7") 
  } 
 
  build() { 
    Column() { 
      Column() { 
        // 页签 
        Row({ space: 7 }) { 
          Image($r('app.media.icon')).onClick(() => { 
          }).width(20).height(20) 
 
          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%') 
          .backgroundColor("#ffb7b7b7") 
 
          Image($r('app.media.icon')).onClick(() => { 
          }).width(20).height(20) 
 
        } 
        .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%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
分享
微博
QQ
微信
回复
2024-06-04 22:43:43


相关问题
Refresh组件不支持设置nestedScroll属性
2428浏览 • 1回复 待解决
web组件不支持localstorage
1174浏览 • 1回复 待解决
HarmonyOS RNOH Image组件不支持apng
327浏览 • 1回复 待解决
Toggle isOn不支持$$?
498浏览 • 1回复 待解决
HarmonyOS 编码集不支持
457浏览 • 1回复 待解决
HarmonyOS 推送设备不支持
392浏览 • 1回复 待解决
linear-gradient不支持start,end属性
1169浏览 • 1回复 待解决
Image组件不支持读入沙盒内的图片
1327浏览 • 1回复 待解决
Image组件不支持svg字符串显示
775浏览 • 1回复 待解决
http类不支持cancel方法
562浏览 • 1回复 待解决