HarmonyOS Flex左右布局时,右边如果有文字,文字则会出现问题

1.使用Row时,左边图片宽度固定时,右边文字被挤出容器

2.使用Flex时,左边图片宽度固定时,右边文字覆盖在左侧图片容器上

@Builder
GoodsListWidget() {
  List() {
    ListItemGroup({ header: this.ListHead(), space: '24lpx' }) {
      ForEach(this.goodsList, (item: GoodsModel) => {
        ListItem() {
          Row() {
            Column() {
              Image(item.Img)
                .width('210lpx')
                .height('100%')
                .borderRadius('16lpx')
            }
            .width('210lpx')
            .height('210lpx')

            Column() {
              Text(item.Name)
                .fontSize('28lpx')
                .fontWeight(FontWeight.Bold)
                .textAlign(TextAlign.Start)
                .border({ width: 1 })
                .width('100%')
              Text(item.Price + '')
                .fontSize('28lpx')
                .fontWeight(FontWeight.Bold)
            }
            .flexGrow(1)
            .alignItems(HorizontalAlign.Start)
            .backgroundColor(Color.Pink)
          }
          .width('100%')
          .padding('24lpx')
          .borderRadius('16lpx')
          .backgroundColor(Color.White)
        }
      }, (item: GoodsModel) => item.ID?.toString())
    }
  }
  .sticky(StickyStyle.Header)
  .edgeEffect(EdgeEffect.None)
  .width('100%')
  .height('100%')
  .padding({ left: '24lpx', right: '24lpx', bottom: '24lpx' })
  .scrollBar(BarState.Off)
  .nestedScroll({
    scrollForward: NestedScrollMode.PARENT_FIRST,
    scrollBackward: NestedScrollMode.SELF_FIRST
  })
}
  • 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.
HarmonyOS
2024-12-24 16:29:46
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

请尝试这个demo:

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Flex() {
      Image($r("app.media.background"))
        .width('240lpx')
          // .height('100%')
        .borderRadius('16lpx')
      Column() {
        Text("[SPA足疗按摩],6店通用 【周末加假日同意】 ")
          .fontSize('28lpx')
          .fontWeight(FontWeight.Bold)
          .textAlign(TextAlign.Start)
          .border({ width: 1 })
        Text("648")
          .fontSize('28lpx')
          .fontWeight(FontWeight.Bold)
      }
      .alignItems(HorizontalAlign.Start)
      .backgroundColor(Color.Pink)
    }
    .width('100%')
    .padding('24lpx')
    .borderRadius('16lpx')
    .backgroundColor(Color.White)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-24 17:49:44
相关问题
HarmonyOS 文字和图片相对布局问题
644浏览 • 1回复 待解决
HarmonyOS 编译curl出现问题
1753浏览 • 1回复 待解决
HarmonyOS Flex 布局设置问题
1464浏览 • 1回复 待解决
HarmonyOS 文字显示问题
1023浏览 • 1回复 待解决
【bearpi】hb build -f出现问题
1434浏览 • 0回复 待解决
HarmonyOS 图片+文字排列问题
700浏览 • 1回复 待解决
HarmonyOS 文字背景局部拉伸问题
635浏览 • 1回复 待解决
编译出现问题,请问怎么解决?
1230浏览 • 1回复 待解决
js采集声音出现问题怎么处理?
4183浏览 • 1回复 待解决