【问题标题】:How to fix text overflowing TextView with padding android:ellipsize="marquee"如何使用填充 android:ellipsize="marquee" 修复溢出 TextView 的文本
【发布时间】:2016-02-20 03:55:41
【问题描述】:

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

在配备 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" />

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

【问题讨论】:

    标签: android textview ellipsis nexus-5


    【解决方案1】:

    您的问题是 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>
    

    因此,我们的想法是创建一个带有内边距、边距和背景的包装容器。 (如果您只有几个这样的视图,那么性能开销应该不会太大)


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

    1. 先尝试删除属性一个一个检查结果
    2. 您可以尝试在容器上指定填充而不是文本视图
    3. 从您的布局看来,您可以尝试这样的事情 而不是文本视图上的“match_parent”:

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

    【讨论】:

    • 谢谢 Gregory,但我现在没有时间验证,但如果在 5 天内没有其他人回答,我会给你赏金.. 否则赏金将消失:P ..“但目前”主要问题仍然存在..为什么它不会出现在带有 Android K 和 L 的三星 Galaxy S3 和 S6 上。
    • @WojtekDmyszewicz 想提供一些关于如何开始修复/解决此问题的想法。如果您可以提供代码有问题的代码(我的意思是容器 + 文本视图),将对其进行更多研究
    • 如果问题没有得到解答,为什么要赏金?文本视图位于与父级(相对布局)底部对齐的线性布局(标题为文本视图)内。问题的核心是:为什么这种溢出会发生在一侧,在某些设备上。请证明解决方案 3 可行。
    • @JessevanMuijden 看来我误解了这个问题)。以为 Wojtek 有两个文本视图。很快就会更新我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多