方式一:
@Entry @Component struct test { build() { Row() { Column() { Text('长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串') .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) }.layoutWeight(1).backgroundColor(Color.Pink) Column() { Text('固定长度') }.width(100) } .width('90%') .height(100) .margin({ top: 100 }) .justifyContent(FlexAlign.Start) .border({ width: 1 }) } }
方式二: @Entry @Component struct test { build() { Row() { Column() { Text('长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串长字符串') .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) .constraintSize({maxWidth:'calc(100% - 100vp)'}) }.flexGrow(1).backgroundColor(Color.Pink) Column() { Text('固定长度') }.width(100) }.width('90%').height(100).margin({ top: 100 }).justifyContent(FlexAlign.Start).border({width:1}) } }