Tabs的tabbar在Scrollable的模式下,如何实现整体tabbar的位置靠左对齐

Tabs的tabbar在Scrollable的模式下,如何实现整体tabbar的位置靠左对齐

HarmonyOS
2024-02-20 10:56:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
wjmfzsz

示例代码

// xxx.ets 
@Entry 
@Component 
struct Index { 
  @State tabArray: Array<number> = [0, 1]; 
  @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(120) 
    .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 }) { 
          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%') 
          .backgroundColor('#FFB7B7B7') 
 
          Image($r('app.media.ic_empty')).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('#1890FF52') 
          }) 
        } 
 
        .barHeight(0) 
        .animationDuration(100) 
        .onChange((index: number) => { 
          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.
分享
微博
QQ
微信
回复1
2024-02-20 19:57:54
相关问题
HarmonyOS tabstabbar整体位置调整
565浏览 • 1回复 待解决
Tabs组件tabBar,能否设置对齐方法?
1180浏览 • 1回复 待解决
HarmonyOS 如何设定tabs组件tabbar样式
1431浏览 • 1回复 待解决
HarmonyOS Tabs组件tabBar宽度问题
1399浏览 • 1回复 待解决
HarmonyOS tabstabBar怎么居左
1173浏览 • 1回复 待解决
如何TabstabBar,添加其他组件
1519浏览 • 1回复 待解决
HarmonyOS 自定义tabbar对齐
640浏览 • 1回复 待解决
关于Tabs里面tabBar样式问题
1029浏览 • 2回复 待解决
HarmonyOS Tabs 组件无法隐藏 tabbar
1418浏览 • 1回复 待解决
实现tabBar多个tab滚动
1098浏览 • 1回复 待解决
HarmonyOS Tabs组件Tabs如何对齐
1245浏览 • 1回复 待解决