如何为textView设置正确的文本(我已将textView的方向设置为RTL)

4

我想设定英文和波斯语混合的文本,但显示的文本不正确。

例如: " cpu چیست؟ "

我设置了TextView的Direction属性并将gravity设置为right!

如何给出正确的文本实例: " چیست؟ Cpu "

这个问题发生在第一个术语是英文时。

布局的主要代码:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="rtl"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1_define"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:layoutDirection="rtl"
        android:layout_margin="5dp" >

    </ListView>

</LinearLayout>

ListView的子代码:

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
      android:layoutDirection="rtl"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1_title_define"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dp"
        android:gravity="right"
        android:text="cpu چیست؟ "
        android:textDirection="rtl"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

请在TextView中定义的XML代码中提及Textview的代码。 - Anjali
如果您的设备低于4.2,android:textDirection 可能无法按预期工作。 - Alex Cohn
1个回答

2
您可以在字符串的开头添加 U+202b(从右向左嵌入),即使在浏览器中也可以正常工作:

&#x202b;cpu چیست؟


此外,您可以使用‎来强制LTR关键字,即使它是RTL。 - Ali Rezaiyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接