gpt4 book ai didi

java - TextView中的Android文本单词之间的距离很长

转载 作者:行者123 更新时间:2023-12-02 08:44:51 24 4
gpt4 key购买 nike

我从 api 中获取长描述文本,如下所示

  {"status":true,"data":[{"id":674,"product_category_id":1,"child_category_id":1,"child_category_two_id":null,"child_category_three_id":null,"supplier_id":2,"supplier_name":"\u0627\u0644\u0645\u062f\u064a\u0631 \u0627\u0644\u0639\u0627\u0645","option_category_id":null,"tax_id":1,"barcode":0,"low_price":114,"image":"1586519373.jpeg","cost":115,"name_ar":"\u0633\u0644\u0629 \u0627\u0645\u0633\u0648 \u0627\u0644\u063a\u0630\u0627\u0626\u064a\u0629","name_en":"Amso food basket","details_ar":"\u0648\u0627\u062d\u062f \u0643\u064a\u0633 \u0623\u0631\u0632 \u0623\u0628\u0648 \u0643\u0627\u0633  \u062e\u0645\u0633\u0629 \u0643\u064a\u0644\u0648\r\n\u0648\u0627\u062d\u062f \u062d\u0644\u064a\u0628 \u0628\u0648\u062f\u0631\u0629 \u0627\u0644\u0641 \u0648\u062b\u0645\u0627\u0646\u0645\u0627\u0626\u0629 \u062c\u0631\u0627\u0645\r\n\u0648\u0627\u062f \u0632\u064a\u062a \u0627\u0644\u0641 \u0648\u0633\u062a\u0645\u0627\u0626\u0629 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0634\u0639\u064a\u0631\u064a\u0629 \u0627\u0631\u0628\u0639\u0645\u0627\u0626\u0629 \u0648\u062e\u0645\u0633\u0648\u0646 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0645\u0639\u062c\u0648\u0646 \u0637\u0645\u0627\u0637\u0645 \u062b\u0645\u0627\u0646\u0645\u0626\u0629 \u0648\u0639\u0634\u0631 \u062c\u0645\r\n\u062b\u0644\u0627\u062b \u0639\u0644\u0628 \u0641\u0648\u0644 \u0645\u062f\u0645\u0633 \u0627\u0644\u0641 \u0648\u0645\u0627\u0626\u062a\u064a\u0646 \u062c\u0645\r\n\u062b\u0644\u0627\u062b \u0639\u0644\u0628 \u062a\u0648\u0646\u0629 \u062e\u0645\u0633\u0645\u0627\u0626\u0629 \u0648\u062e\u0645\u0633\u0648\u0646 \u062c\u0645\r\n\u0648\u0627\u062d\u062f \u0633\u0643\u0631 \u0627\u062b\u0646\u064a\u0646 \u0643\u064a\u0644\u0648\r\n\u0627\u062b\u0646\u064a\u0646 \u0645\u0639\u0643\u0631\u0648\u0646\u0629 \u0645\u062a\u0646\u0648\u0639\u0647 \u0627\u0644\u0641 \u062c\u0645","details_en":"one Abu kas rice five kg   one powdered milk on thousand and eight hundred gm one vegetable oil on thousand and six hundred gm one fine noodles four hundred fifty gm  one tomato paste eight hundred and ten gm three beans cans   three tuna cans  one sugar two Kg two  mixed pasta one kg","sumInv":500,"campaign":{"id":null,"product_id":null,"price":null,"purchasesLimits":null,"stock":null},"packages":[{"package_id":2436,"package_price":"114.2900","unit_count":1,"existing":0,"virtual":500}]}],"last_page":1,"current_page":1,"per_page":16}

,但是当我在 TextView 中显示时出现问题,我得到了这个奇怪的结果

enter image description here enter image description here

在阿拉伯语和英语中,它看起来有所不同,在阿拉伯语中,几乎每个单词之间都有空格,但在英语中,它出现在第 1,2 和 3 行的一些单词之前。

这是 TextView 上的代码,其中容器是约束布局

<TextView
android:id="@+id/tv_activity_detail_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textSize="12dp"
android:textColor="@color/colorDarkGray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView" />

最佳答案

我发现了 unicode 字符的问题,所以当我尝试使用它的 unicode 字符显示文本时,它给了我当前屏幕,但我得到了这个 Unicode 的真实文本并且显示得很好,无论如何我通过使用找到了解决方案java 中的 HTML 文本:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml(user.getInput(), Html.FROM_HTML_MODE_LEGACY));
} else {
textView.setText(Html.fromHtml(user.getInput()));
}

我从这个answer得到了解决方案

关于java - TextView中的Android文本单词之间的距离很长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61149541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com