HarmonyOS Text超出显示省略号

text组件使用textOverflow({ overflow: TextOverflow.Ellipsis }) maxLines(1)限制超出一行显示省略号时,如果中文前面和后面有数字和字母就会裁剪异常。

HarmonyOS
2024-10-08 10:28:57
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

设置设置断行规则WordBreak.BREAK_ALL即可,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5#wordbreak11

参考demo如下:

@Entry  
@Component  
struct ChildComponent {  
  @State text: string = '黑龙江_12aadfdafdjdda..fsajfdi'  
  build() {  
    Column() {  
      Text(this.text)  
        .width(200)  
        .maxLines(1)  
        .textOverflow({ overflow: TextOverflow.Ellipsis })  
        .ellipsisMode(EllipsisMode.END)  
        .wordBreak(WordBreak.BREAK_ALL)  
    }  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
分享
微博
QQ
微信
回复
2024-10-08 17:23:50
相关问题
HarmonyOS Text 超出限制显示一个更多
688浏览 • 1回复 待解决
HarmonyOS Text显示异常
509浏览 • 1回复 待解决
多行文本省略的展开与显示
1914浏览 • 1回复 待解决