1 个回答

flexBasis(‘auto’)默认展示基准尺寸是元素本来的大小,组件原本默认多大设置flexBasis(‘auto’)后就有多大,并不会自动扩大或缩小,如果设置了width,则使用width的宽度。

示例代码

@Entry
@Component
export struct Index {
  @State message: string = '这是一个标题可能很长很长很长很很长很长很';
  @State message1: string = '2024-1-12 12:00:001111111';

  build() {
    Flex({
      justifyContent:FlexAlign.SpaceBetween,
      alignContent: FlexAlign.Center
    }) {
      Text(this.message)
        .flexShrink(1)
        .fontSize(17)
        .fontWeight(FontWeight.Bold)
        .backgroundColor(Color.Yellow)
        .maxLines(1)
        .textOverflow({overflow: TextOverflow.Ellipsis})
      //.wordBreak(WordBreak.BREAK_ALL)
      Text(this.message1)
        .flexShrink(0)
        .fontSize('14')
        .maxLines(1)
        .backgroundColor(Color.Grey)
        .textAlign(TextAlign.End)
    }.backgroundColor("#EBEBEB")
    .width("90%")
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进