【问题标题】:Android text gets clipped on some devicesAndroid 文本在某些设备上被截断
【发布时间】:2014-04-29 22:18:43
【问题描述】:

我在一部手机中遇到问题(直到现在)。我的应用程序使用印地语字体。它在模拟器、选项卡和许多其他手机上也能很好地显示。但是我用于测试目的的一部手机显示文字从侧面切开。

我几乎尝试了所有方法来将其按正确的顺序排列,但都没有奏效。这里贴出我的两部测试手机的截图和文字。

有错误的截图:

其他手机的截图:和预期的一样:

可能是什么原因,我该如何解决?请告诉我!!

我正在使用的 TextView 配置:

<TextView
    android:id="@+id/A_lbl_mandir"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/Abt_mandir"
    android:textAlignment="center"
    android:textColor="#80000A"
    android:textSize="35sp" />

编辑:我的完整活动 xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:id="@+id/text"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/hello_world" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/text" >
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:padding="5sp"
    android:text="@string/test"/>
</ScrollView>

</RelativeLayout>

我已经尝试并删除了许多其他东西,尤其是这款手机。但无法解决问题!

【问题讨论】:

  • 谢谢维格!得到了低分,所以无法发布图片。 :)
  • 你试过了吗? textView.setText(Html.fromHtml(yourtext));
  • 是的!我也通过 setText 尝试过....但文本仍然被剪辑
  • 我希望你在使用 setText 时尝试过 Html.fromHtml。
  • 是的,我做到了。我的输出很好...... setText(Html.fromHtml(text)) 使用没有错误,我唯一的问题是文本切割。 n 那也是,印地语文本,n 那仅适用于特定电话。在我的其他手机或模拟器中,它工作得很好......上面的两个屏幕截图都是两部不同的手机,其中一个我遇到了问题,第二个是我在其他手机和模拟器上得到的预期和输出。跨度>

标签: android text textview clip


【解决方案1】:

这发生在 4.1.2 中,它被记录为 Google 中的一个错误,他们已在 4.2 中修复。

https://code.google.com/p/android/issues/detail?id=34432

Android 操作系统无法计算文本长度的 unicode 字体会发生这种情况。

【讨论】:

    【解决方案2】:

    好吧!发现另一部有同样问题的手机。在那部手机中,文本也被剪掉了。估计是手机有问题。因为即使是像 Whatsapp 这样的流行应用程序也在该设备上遇到了同样的问题。印地语文本的剪切与上图相同。

    解决该问题的可能方法:(如果有人知道我现在正在做的事情。)我意识到浏览器可以很好地显示印地语字体。所以最好在 html、javascript 上制作一个原生应用程序,尤其是对于此类设备,并使用 WebView 查看 HTML。应用程序会变得有点慢,但我们必须这样做,直到我们遇到创建它的实际问题。

    请注意:这不是解决方案,而是解决问题的方法。在印地语中被称为“JUGAAD”。

    【讨论】:

      【解决方案3】:

      试试这个。

      <ScrollView
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:layout_marginLeft="10dp"
      android:layout_marginRight="10dp"
      android:layout_below="@id/text" 
      android:padding="5dp">
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:gravity="left" 
        android:padding="5sp"
        android:text="@string/test"/>
      </ScrollView>
      

      【讨论】:

      • 然后尝试使用 android:layout_marginLeft="10dp" android:layout_marginRight="10dp" 与填充。
      • 把你的完整的xml文件。 at 列出布局,其中包含 Textview。
      • 完成。请先生看看。
      • 嘿@yours.akshit,如果你仍然有问题,那么做一些技巧来确定什么是实际问题。为滚动视图、文本视图和相对布局提供不同的背景颜色。
      • 嗯……我什么都试过了,我从堆栈溢出搜索中得到的每一个结果,改变了背景,填充,字体大小,但仍然……这部手机对我来说是个问题。会不会是手机的问题?有什么想法可以检查一下吗?因为我从 Playstore 下载了一个印地语思想应用程序只是为了检查同样的问题。 n 文本也被剪辑在该应用程序中......在我的其他手机上工作正常。你们是我最后的希望!
      【解决方案4】:

      在某些手机(特别是三星手机)上,某些自定义字体会被截断(或剪裁)。我有这个自定义斜体字体。有人说您可以编辑字体以添加某种填充(我无法确认,因为我缺乏编辑字体的知识)但是: - EditText/TextView 从 xml 添加一些填充 - 椭圆(在某些设备上弄乱这有助于正确显示文本)

      您还可以发布屏幕截图并启用开发人员选项以绘制布局边界,如果上述解决方案没有帮助,这可能有助于解决您的问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 2014-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多