想实现tabBar多个tab滚动的

想实现tabBar多个tab滚动的,但是用系统默认的tab传一个字符串 可以根据文字长度自适应大小,但是用了自定义tabbar内容就是默认占满一行了。

HarmonyOS
2024-09-23 14:05:21
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考:

@Entry  
@Component  
struct TabsOpaque {  
  private controller: TabsController = new TabsController()  
  
  build() {  
    Column() {  
  
      Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Pink)  
        }.tabBar(SubTabBarStyle.of('pink')  
          .indicator({  
            color: Color.Red, //下划线颜色  
            height: 2, //下划线高度  
            width: 40, //下划线宽度  
            borderRadius: 1, //下划线圆角半径  
            marginTop: 2 //下划线与文字间距  
          })  
          .selectedMode(SelectedMode.INDICATOR)  
          .board({ borderRadius: 20 })  
          .labelStyle({})  
        )  
  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Yellow)  
        }.tabBar(new SubTabBarStyle("pikk"))  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Blue)  
        }.tabBar('blue')  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Green)  
        }.tabBar('green')  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Green)  
        }.tabBar('green')  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Green)  
        }.tabBar('green')  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Green)  
        }.tabBar('green')  
  
        TabContent() {  
          Column().width('100%').height('100%').backgroundColor(Color.Green)  
        }.tabBar('green')  
      }  
      .vertical(false)  
      .scrollable(true)  
      .barMode(BarMode.Scrollable)  
      .barHeight(80)  
      .animationDuration(400)  
      .onChange((index: number) => {  
        console.info(index.toString())  
      })  
      .fadingEdge(false)  
      .height('30%')  
      .width('100%')  
  
  
    }  
    .padding({ top: '24vp', left: '24vp', right: '24vp' })  
  }  
}
  • 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.
分享
微博
QQ
微信
回复
2024-09-23 17:46:07
相关问题
HarmonyOS 怎么自定义TabTabbar
755浏览 • 1回复 待解决
HarmonyOS 怎么配置tab默认选择tabBar
1063浏览 • 1回复 待解决
Tab组件Tabbar中字体颜色如何修改
2362浏览 • 1回复 待解决
HarmonyOS Tabs组件Tab滚动问题
1578浏览 • 1回复 待解决
Tab导航栏tabbar子组件突出上沿显示
3119浏览 • 1回复 待解决