如何使文本方向从右到左 [英] How to make the text direction from right to left

查看:15
本文介绍了如何使文本方向从右到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 TextView 中用(从右到左的语言,即阿拉伯语)编写文本.但我想让文字书写方向从右到左.gravity:right只会将文本右对齐.我想从右到左对齐文本(使单词和数字出现在他输入的行中).怎么样?

I want to write text in (right to left language i.e. Arabic) in a TextView. But I want to make the text writing direction from right to left. gravity:rightwill align the text to right only. I want to justify the text from right to left ( to make the words and numbers appear in he entered order in the line ) . how ?

推荐答案

另一种巧妙的方法可以在旧版本的 android 中使用,并且可以在字符串中的任何位置使用,因此即使在最新版本的 android 中也更方便,是包含从右到左的标记,甚至是从左到右的标记,如果需要的话:

Another clever way which can be used in older versions of android and can be used anywhere in string so it's handier even in latest version of android, is to include the right-to-left mark or even left-to-right mark in the string when it's needed:

left-to-right mark: ‎ or ‎ (U+200E)
right-to-left mark: ‏ or ‏ (U+200F)

事情是这样的:

String rtl = "Hello u200F(سلام)";

这种方法的好处是,您甚至可以在 标点符号(如 (,{,[,!) 后使用它,这些标点符号位置不正确!示例:

The good thing about this method is you can even use it after punctuation like (,{,[,! which are positioned right incorrectly! examples:

سلام! // wrong position
سلام!‏ // right position by adding RLM after !

看看!在第二行是如何正确定位的,其实后面有一个RLM,就算看不见也可以复制粘贴.

look how ! is positioned correctly in second line, actually there is an RLM after it, and you can copy paste it even if it's invisible.

您看到的第二个好处是您可以在任何支持 RTL 的系统(如浏览器、word 等)中使用此方法(这些字符代码).

The second good thing as you saw it is that you can use this method (these char codes) in any system that supports RTL like browsers, word and so on.

这篇关于如何使文本方向从右到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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