Man*_*ser 40 android word-wrap hyphenation textview
作为国际化Android应用程序的一部分,我遇到了在正确位置动态自动换行或连字符的需求.
我的所有字符串都在strings.xml文件中外部化,但我没有在Android中找到任何关于连字符的文档.
我希望能够建议类似于我在LaTeX中如何做的连字位置:
http://en.wikipedia.org/wiki/Hyphenation_algorithm
但是,如果可能的话,没有发现任何迹象?我错过了框架中的任何内容吗?还有其他人在做什么,例如日语字符串没有明显的位置可以分解句子?你只是在正确的位置添加空格吗?
我可以动态调整字体大小以适应某些布局,但是对于跨越多行不能工作的更长消息.该怎么办?
小智 7
换行管理可能很麻烦.最好的选择是使用UTF换行符修饰符控制字符,因为android支持完整的UTF
我知道有人提到"软连字符",但还有更多.
您还可以在缺少空格的语言之间使用单词之间的"零宽度空间",这样您就不必依赖字典解释.您也可以将此作为软连字符用于允许在某些点上突破某些单词的语言.
当使用您不想破坏的复合词时,但是您希望Text To Speech系统能够正确识别它时,您应该使用"Word Separator"字符.不要使用"Zero Width Non Breaking Space",因为它被用作BOM.
最后,如果您想要一个空格但不想换行,请使用简单的不间断空格.
软连字符适用于从 Android 4.3 开始的三星 Galaxy 设备。
<!-- key combination to enter soft hyphen: [Alt Gr]+[-] or [Alt]+240 on German PC, see https://de.wikipedia.org/wiki/Weiches_Trennzeichen#Darstellung_auf_Computersystemen -->
<string name="no_connection">Nicht ver-bund-en</string>
Run Code Online (Sandbox Code Playgroud)
由于我的用例非常狭窄,我只在“verbunden”一词中使用了一个软连字符。Unicode \u00ad 没有效果。
小智 6
这是Android 6 Marshmellow的新功能。
尝试将其添加到您的TextView xml
android:hyphenationFrequency="none"
Run Code Online (Sandbox Code Playgroud)
以下库支持连字.它为您执行所有类型的文本对齐(左/右/中心/对齐)和连字符.并非所有语言都已添加,但可以根据需要添加.此库使用NO WEBVIEWS和SUPPORTS SPANNABLES并允许长文本.
图书馆:https://github.com/bluejamesbond/TextJustify-Android
ANDROID:2.2到5.X
建立
DocumentView documentView = addDocumentView(new StringBuilder("Your long text content"), DocumentView.PLAIN_TEXT);
documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
documentView.getDocumentLayoutParams().setHyphenator(new Hyphenator(HyphenPattern.PT));
documentView.getDocumentLayoutParams().setHyphenated(true);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17014 次 |
最近记录: |