HarmonyOS row包含一个image,一个text,text会超过row的边界

row包含一个image,一个text,text会超过row的边界(改成用imageSpan没问题)

@Component 
export struct VSOrderDetailAddressCell { 
  @Consume(OrderDetailProvider.viewModel) viewModel: OrderDetailViewModel 
 
  build() { 
    if (!this.viewModel.isShowTrack() && (isNotNullOrUndefined(this.viewModel.orderDetail?.tradeInShopInfo) || this.viewModel.isShowAddressInTop())) { 
      Column({space: 4}) { 
        Row({space: 8}) { 
          Image($r('app.media.order_icon_address_gradinet')).width(21).height(21) 
          Text() { 
            if (isStringAndNotEmpty(this.viewModel.orderDetail?.buyer)) { 
              Span(this.viewModel.orderDetail?.buyer) 
            } 
            if (isStringAndNotEmpty(this.viewModel.orderDetail?.mobile)) { 
              Span((isStringAndNotEmpty(this.viewModel.orderDetail?.buyer) ? '   ' : '') + this.viewModel.orderDetail?.mobile) 
            } 
          }.fontColor(0x1B1B1B).fontSize(16).fontWeight(FontWeight.Medium).backgroundColor(Color.Red) 
          if (this.viewModel.canShowModifyAddressButton()) { 
            Blank() 
            Text('修改').fontSize(11).fontColor(0x5F5F5F).height(20).padding({left: 8, right: 8}).height(20).onClick(() => { 
 
            }) 
          } 
        }.width('100%').alignItems(VerticalAlign.Top).backgroundColor(Color.Green) 
        Text((this.viewModel.orderDetail?.area_name??'') + (this.viewModel.orderDetail?.address??'')).fontSize(12).fontColor(0x5F5F5F).width('100%') 
      }.backgroundColor(Color.White).margin({left: this.viewModel.cardGap, right: this.viewModel.cardGap}).borderRadius(this.viewModel.cardRadius) 
      .padding({left: this.viewModel.cardPadding, right: this.viewModel.cardPadding, top: 15, bottom: 15}).alignItems(HorizontalAlign.Start) 
    } 
  } 
}
HarmonyOS
2024-08-08 16:17:56
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

Row布局时,若子组件不设置flexShrink则默认不会压缩子组件,即所有子组件主轴大小累加可超过容器主轴。 可以对子组件设置layoutWeight(1)进行解决

分享
微博
QQ
微信
回复
2024-08-08 20:23:12
相关问题
HarmonyOS Text 超出限制显示一个更多
48浏览 • 1回复 待解决