【问题标题】:TextView Ellipsize not workingTextView Ellipsize 不起作用
【发布时间】:2015-06-01 10:24:23
【问题描述】:

下面是xml中定义的TextView。

     <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Select Language"
            android:singleLine="true"
            android:maxLines="1"
            android:maxLength="30"
            android:ellipsize="end"
            android:padding="4dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/holo_blue_dark"
            android:id="@+id/selected_language" />

当文本长度大于 30 个字符但它根本不起作用时,我想省略文本。请检查我是否遗漏了任何内容。我尝试了针对类似问题发布的答案,但它不起作用。

【问题讨论】:

    标签: android textview


    【解决方案1】:

    我已在您的 TextView 中将 MaxLength 更改为 MaxEms,现在使用它。

    <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="Select Language"
                android:singleLine="true"
                android:maxLines="1"
                android:maxEms="30"
                android:ellipsize="end"
                android:padding="4dp"
                android:textAppearance="?android:textAppearanceMedium"
                android:textColor="@android:color/holo_blue_dark"
                android:id="@+id/selected_language" />
    

    【讨论】:

    • EMS从不代表字符长度。所以这是一个错误的解决方案。
    【解决方案2】:

    ellipsize 不会根据最大长度工作 它适用于您的文本视图的宽度。

    在您的代码中,您提到 maxlength 30 所以尝试指定 textview 的宽度。

    【讨论】:

      【解决方案3】:

      感谢您的回答。 我删除了 maxLength 属性并将其宽度设置为 match_parent.its 现在可以工作。

      【讨论】:

        猜你喜欢
        • 2014-03-14
        • 2013-01-19
        • 2012-06-30
        • 2018-05-29
        • 2021-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-22
        相关资源
        最近更新 更多