防止TextView中的断字 [英] Prevent word-break in a TextView
本文介绍了防止TextView中的断字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个宽度固定的TextView
,如下所示:
I have a TextView
with fixed width as follows:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="12sp"
tools:text="Health Department"
android:layout_marginTop="4dp"
android:maxLines="2"
/>
...但是它看起来像:
... But it appears like:
|Health Dep-|
| artment |
...我希望它是:
| Health |
|Department|
我可以使用什么XML属性来做到这一点?
What XML attribute can I use to do this?
推荐答案
在api 23中,您可以选择中断策略,该策略应该可以解决您的问题.
From api 23 you can choose the break strategy and that should fix your issue.
默认情况下,用于TextView的android使用 BREAK_STRATEGY_HIGH_QUALITY ,即导致使用连字符打断单词.
By default android for TextView use BREAK_STRATEGY_HIGH_QUALITY and that is causing the words breaking using hyphens.
如果要避免这种情况,可以将中断策略设置为 BREAK_STRATEGY_SIMPLE .
If you want to avoid that, you can set the break strategy to BREAK_STRATEGY_SIMPLE.
您可以在 API文档中找到更多信息.
希望对您有所帮助.
这篇关于防止TextView中的断字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文