HarmonyOS Column中子View的宽度如何根据Column的实际宽度进行自适应

Column(){
  Text(item.name)
    .fontColor(this.selectIndex === index ? $r('app.color.color_main'): $r('app.color.color_333333'))
    .fontWeight(this.selectIndex === index ? FontWeight.Medium : FontWeight.Regular)
    .fontSize(16)
    .margin({top:16})
  Shape()
    .width(48)
    .height(2)
    .borderRadius(2)
    .backgroundColor($r('app.color.color_main'))
    .margin({top:7})
    .visibility(this.selectIndex===index?Visibility.Visible:Visibility.Hidden)
}.height(44)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

Shape的宽度 如何根据Text宽度进行自适应

HarmonyOS
2024-12-24 16:52:41
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

这是个简易demo

@Entry
@Component
struct TabsOpaque {
  text: ResourceStr | undefined;
  @State message: string = 'Hello World'
  private controller: TabsController = new TabsController()
  @State selfFadingFade: boolean = true;

  build() {
    Column(){
      Stack({ alignContent: Alignment.Top }){
        Row(){
          Image($r('app.media.ic_more'))
            .width(20)
            .height(20)
        }
        .backgroundColor('#808080')
        .height(40)
        .width('100%')
        .justifyContent(FlexAlign.End)
        .flexShrink(1)
        .justifyContent(FlexAlign.End)
        .onClick(()=>{
          console.log('更多')
        })
        Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Pink)
          }.tabBar('一键执法')

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Yellow)
          }.tabBar('应急公务')

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Blue)
          }.tabBar('执法执勤')

          TabContent() {
            Column().width('100%').height('100%').backgroundColor(Color.Pink)
          }.tabBar('补录')
        }
        .vertical(false)
        .scrollable(true)
        .fadingEdge(true)
        .barMode(BarMode.Fixed)
        .barHeight(40)
        .animationDuration(400)
        .onChange((index: number) => {
          console.info(index.toString())
        })
        .width('100%')
      }

    }.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.
分享
微博
QQ
微信
回复
2024-12-24 19:32:09


相关问题
HarmonyOS grid如何自适应宽度
538浏览 • 1回复 待解决
HarmonyOS popup宽度自适应
362浏览 • 1回复 待解决
HarmonyOS Image如何设置内容宽度自适应
445浏览 • 1回复 待解决
HarmonyOS List高度根据内容自适应
620浏览 • 1回复 待解决
HarmonyOS Grid高度根据内容自适应
475浏览 • 1回复 待解决