【问题标题】:How to set correct text to textView (I am set RTL in Direction of textView)如何为textView设置正确的文本(我在textView的方向设置了RTL)
【发布时间】:2026-01-22 23:00:01
【问题描述】:

我想设置 English 和 Persian 的文本组合。但显示的文字不正确

实例:“cpu 带入”

我在 TextView 中设置了方向属性并将重力设置为右!!!

如何才能给出正确的文本实例:“带入 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中定义的Textview的xml代码
  • 如果您的设备低于 4.2,android:textDirection 可能无法正常工作。

标签: java android textview attr right-to-left


【解决方案1】:

您可以在字符串的开头添加 U+202b(从右到左嵌入),即使在浏览器中也适用于我:

&amp;#x202b;cpu چیست؟

【讨论】:

  • 另外,你可以使用 ‎强制 LTR 关键字事件是 RTL