在HarmonyOS NEXT开发中Tabs TabBuild高度被系统限定?

在HarmonyOS NEXT开发中Tabs TabBuild高度被系统限定?

阅读 843
1 个回答

解决方案如下:

@Entry 
@Component 
struct TabsKeyPage { 
  @State keys: Array<string> = [] 
 
  aboutToAppear(): void { 
    for (let i = 0; i < 4; i++) { 
      this.keys.push(i.toString()) 
    } 
    console.log("tag", JSON.stringify(this.keys)); 
  } 
 
  @Builder 
  tabBuilder(index: number, name: string) { 
    Column() { 
      Text(name) 
        .fontSize(16) 
        .lineHeight(22) 
        .margin({ top: 17, bottom: 7 }) 
      Divider() 
        .strokeWidth(2) 
        .color('#007DFF') 
    } 
    .width('100%') 
 
    // .height("200") 
  } 
 
  build() { 
    RelativeContainer() { 
      Tabs() { 
        ForEach(this.keys, (item: string, index: number) => { 
          TabContent() { 
            Text("AAAAAAAAAAAAA").width("100%").fontColor(Color.Green).fontSize(30).height("100%") 
          } 
          .tabBar(this.tabBuilder(0, 'green')) 
        }) 
      } 
      .barHeight(200) 
      // .height('100%') 
      .width('100%') 
      .backgroundColor(Color.White) 
    } 
    .height('100%') 
    .width('100%') 
  } 
}

设置barHeight的值可改变高度,但要注意其他注释的height,如果设置了,该值无效。
关于barHeight的说明规则请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
还有一些其他实现方法也可参考:https://developer.huawei.com/consumer/cn/forum/topic/02031421...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进