Android中的断字 [英] Hyphenation in Android

查看:153
本文介绍了Android中的断字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为国际化Android应用程序的一部分,我遇到了在适当位置动态自动换行或断字的需求.

As part of internationalizing an Android application I have come across the need to dynamically word wrap or hyphenate at the right position.

我所有的字符串都被外部化在strings.xml文件中,但是我在Android中找不到有关连字符的任何文档.

All my strings are externalized in strings.xml files but I have not found any documentation about hyphenation in Android.

我希望能够提出连字符的位置,类似于我在LaTeX中的操作方式:

I would like to be able to suggest hyphenation positions similar to how I can do it in LaTeX:

http://en.wikipedia.org/wiki/Hyphenation_algorithm

但是我没有找到任何迹象表明这是可能的.我错过了框架中的任何内容吗?其他人在做什么,例如没有明显的分句位置的日语字符串?您只是在正确的位置添加空格吗?

But I have not found any indication if this is possible. Is there anything in the framework I have missed? What are other people doing e.g. with Japanese strings that have no obvious position to break up a sentence? Do you just add spaces at the correct positions?

我可以动态调整字体大小以适合某些布局,但是对于跨多行的较长消息不起作用.该怎么办?

I could dynamically size the font to fit into certain layouts but for longer messages that go across multiple lines that won't work. What to do?

推荐答案

换行管理可能很麻烦.最好的选择是使用utf换行修饰符控制字符,因为android支持完整的utf

Management of line breaks can be a hassle. The best option is to use UTF line-break modifier control characters since android supports full UTF

我知道有人提到软连字符",但还有很多.

I know someone mentioned "soft-hyphen", but there are quite a few more.

您还可以在缺少空格的语言上的单词之间使用零宽度空格",因此您不必依赖词典解释.您还可以将其用作语言中的软连字符,这些语言允许在某些点的行上打断某些单词.

You can also use the "Zero Width Space" between words on languages that lack spaces so you don't have to rely on dictionary interpretation. You can also use this as a soft-hyphen in languages that allow breaking of certain words over lines at certain points.

当您使用不想破坏的复合词但希望文本转语音"系统正确识别它时,应使用词分隔符"字符.请勿使用零宽度不间断空格",因为它已被用作BOM,因此已被弃用.

When using a compound word that you don't want broken, but you want the Text To Speech system to recognize it properly you should use "Word Separator" character. Don't use "Zero Width Non Breaking Space" as that has been deprecated due to it's use as BOM.

最后,如果您想要一个空格但又不想换行,请使用一个简单的不间断空格.

Finally, if you want a space but don't want a line break, use a simple non-breaking space.

这篇关于Android中的断字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆