赞
踩
HarmonyOS Text 默认是显示一行,想要Text超出部分末尾显示...
设置 truncation_mode="ellipsis_at_end" 即可,
truncation_mode 还有其他的属性, 当truncation_mode="ellipsis_at_start" 设置为true是点点在文字开头显示,当 truncation_mode="ellipsis_at_middle" 在中间的时候点点在中间显示.
xml 代码如下
- <?xml version="1.0" encoding="utf-8"?>
- <DirectionalLayout
- xmlns:ohos="http://schemas.huawei.com/res/ohos"
- ohos:height="match_parent"
- ohos:width="match_parent"
- ohos:orientation="vertical">
-
- <Text
- ohos:id="$+id:text"
- ohos:height="match_content"
- ohos:width="200vp"
- ohos:text="窗前明月光,疑是地上霜."
- ohos:text_size="22fp"
- ohos:truncation_mode="ellipsis_at_end"
- ohos:top_margin="50vp"/>
-
- <Text
- ohos:id="$+id:text1"
- ohos:height="match_content"
- ohos:width="200vp"
- ohos:text="窗前明月光,疑是地上霜."
- ohos:text_size="22fp"
- ohos:truncation_mode="ellipsis_at_start"
- ohos:top_margin="50vp"/>
-
- <Text
- ohos:id="$+id:text2"
- ohos:height="match_content"
- ohos:width="200vp"
- ohos:text="窗前明月光,疑是地上霜."
- ohos:text_size="22fp"
- ohos:truncation_mode="ellipsis_at_middle"
- ohos:top_margin="50vp"/>
-
- </DirectionalLayout>
效果图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。