java - 如何将正确的文本设置为 textView(我在 textView 的方向设置了 RTL)

标签 java android textview attr right-to-left

我想要设置英语和波斯语的文本合成。但是显示的文字不正确

实例:“cpu ?

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

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

这个问题出现在第一学期英语的时候。

Layout主要代码:

 <?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>

最佳答案

您可以在字符串的开头添加 U+202b(从右到左嵌入),这对我来说甚至在浏览器中也适用:

&#x202b;cpu چیست؟

关于java - 如何将正确的文本设置为 textView(我在 textView 的方向设置了 RTL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625469/

相关文章:

java - 如何在 TextView 中显示阿拉伯文本

java - Android - 运算符和 TextView 值出现问题

java - 您如何使用 Google DataProc Java 客户端使用关联的 GS 存储桶中的 jar 文件和类提交 spark 作业?

java - 在Java中绕过子类中的final方法?

java - 是否有一种规范的方法来确定 HTTP 响应是否在 Java 的 200 系列中?

Swift 3 - 更改 UITextView 选定文本的字体

java - 组合数组索引

java - 如何用 Java 的 for-each 循环填充数组?

java - 如何修复 RN 中的 `cannot be cast to java.lang.String`?

java - 蓝牙适配器服务仍为空