Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

android - How to make the text direction from right to left

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

This is how it's down:

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 !

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...