如何修复文本溢出TextView与填充android:ellipsize =" marquee"

时间:2015-11-18 12:06:32

标签: android textview ellipsis nexus-5

在某些Android设备上(带有Android L和M的LG Google Nexus 5)带有android:ellipsize =" marquee"的TextView和填充导致文本溢出textview。它出现在右侧但不在TextView的左侧,而填充应用于左侧和右侧。

screenshot

分别在Android K和L的三星Galaxy S3和S6上不会出现。

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:freezesText="true"
android:alpha="0.85"
android:background="@color/by433_gray_darker"
android:textColor="@color/white"
android:textSize="11sp" />

我可以做些什么来解决或解决这个问题?

1 个答案:

答案 0 :(得分:2)

您的问题是Android开源项目中的Android和already reported and assigned的错误:

您的解决方法可能如下所示:

<FrameLayout android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:paddingTop="2dp"
             android:paddingBottom="2dp"
             android:paddingLeft="4dp"
             android:paddingRight="4dp"
             android:layout_marginBottom="1dp"
             android:background="@color/by433_gray_darker">
    <TextView
        android:id="@+id/textId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:freezesText="false"
        android:alpha="0.85"
        android:text="super nice text text text text text text text text text text text text text text text text text"
        android:textColor="@color/white"
        android:textSize="11sp" />
</FrameLayout>

因此,我们的想法是拥有一个带有填充,边距和背景的包装容器。 (如果你只有几个这样的观点,它不应该是很大的性能开销)

原始错误答案(虽然有两个TextView) 问题可能是由于TextView上有如此多的属性组合。以下是一些建议:

  1. 首先尝试逐个删除属性检查结果
  2. 您可以尝试在容器上指定填充而不是文本视图
  3. 从您的布局看起来您可以尝试这样的事情 而不是&#34; match_parent&#34;在您的文字观点:

    <LinearLayout android:orientation="horizontal" ...>
        <TextView android:layout_width="0dp" android:layout_weight="1" ... />
        <TextView android:layout_width="0dp" android:layout_weight="1" ... />
    </LinearLayout>