How to make the text direction from right to left

2019-01-10 18:35发布

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 ?

12条回答
一夜七次
2楼-- · 2019-01-10 19:18

best way textDirection for TextView, Don't use layoutDirection

  <TextView
     android:id="@+id/viewCountTv"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textDirection="anyRtl"
     android:gravity="center"/>
查看更多
Explosion°爆炸
3楼-- · 2019-01-10 19:20

Too late , but the android:gravity="right" worked.

查看更多
家丑人穷心不美
4楼-- · 2019-01-10 19:20

Try using

 textview.setTextDirection(View.TEXT_DIRECTION_RTL);

or

 textview.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-10 19:26

set this line in xml for textview :

 android:textDirection="locale"
查看更多
叼着烟拽天下
6楼-- · 2019-01-10 19:27

Just put this property in your TextView and everything will workout just fine it will automatically detect your text and change accordingly

android:textDirection="anyRtl"
查看更多
时光不老,我们不散
7楼-- · 2019-01-10 19:27

By using attributes as below in my xml code strangely I got a right to left text with correct punctuation. But this is not a perfect solution for multi language text:

android:textDirection="ltr"
android:gravity="right"

setting ltr corrects punctuation problems like having dot on right side instead of left.

gravity attribute makes text flow from right to left.

查看更多
登录 后发表回答