以RTL格式格式化时,TextView中的数字会颠倒 [英] Numbers inside TextView getting reversed when formatted in RTL
问题描述
TextView
中的数字在以RTL格式格式化时会被颠倒.当数字位于 TextView
内文本的末尾时,它们将相反.我该如何以编程方式解决此问题?
例如,以下数字是相反的:
它们应显示为:
误解:RTL语言中的数字(如ARABIC)应从RTL写入阿拉伯数字,以避免出现任何问题,例如:تمإرسالرسالةنصيةللرقم١٢٣٤"注意,我写的是رسالةنصية"而不是"SMSرسالة".
问题及其解决方案:混合多个方向语言需要更多步骤,您需要告诉系统嘿,是RTL字,将其添加到序列中".因此,您可能需要隐式执行,即:
\ u200f +تمإرسالرسالةنصيةىلى+数字
考虑StringBuilder:对于开发人员来说,使用 plus (+)表示法为RTL语言开发某些东西是非常痛苦的,这很容易混淆并且容易出错.
更好的方法:
builder.append("\ u061C").append(تمإرسالرسالةنصيةلـ").append("\ u200E").append("+ 0123456789")
请考虑BidiFormatter: 实用程序用于格式化文本以在潜在的相反方向的上下文中显示而不会造成干扰的类
示例:
字符串文本="{0}تمإرسالرسالةنصيةلـ";字符串电话= BidiFormatter.getInstance().unicodeWrap("+ 961 01 234 567");字符串结果= MessageFormat.format(text,phone);
现在,结果
将正确格式化.
Numbers inside TextView
are getting reversed when formatted in RTL.
When numbers are at the end of a text inside a TextView
they getting reversed. How can I solve this programmatically?
As an example, the numbers below are reversed:
They should be displayed like:
The misunderstand: Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة".
The problem and it's solution: Mixing more than one direction languages required more steps, you need to tell the system "hey this is RTL word, add as it to sequence". So you may need to do this implicitly, i.e:
\u200f + تم إرسال رسالة نصية إلى + number
Consider StringBuilder: It's very painful for developer to develop something for RTL language using plus(+) notation, this much confusing and error prone.
A better way:
builder.append("\u061C").append(" تم إرسال رسالة نصية لـ").append("\u200E").append("+0123456789")
Consider BidiFormatter: Utility class for formatting text for display in a potentially opposite-directionality context without garbling
Example:
String text = "{0} تم إرسال رسالة نصية لـ ";
String phone = BidiFormatter.getInstance().unicodeWrap("+961 01 234 567");
String result = MessageFormat.format(text,phone);
Now, result
will be formatted properly.
More examples on how BidiFormatter work.
这篇关于以RTL格式格式化时,TextView中的数字会颠倒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!