android - TextView 椭圆大小不工作

标签 android textview

下面是在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 个字符时将文本省略,但它根本不起作用。请检查我是否遗漏了任何内容。我尝试了针对类似问题发布的答案,但它没有用。

最佳答案

我已经在您的 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" />

关于android - TextView 椭圆大小不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30571067/

相关文章:

android - TextView setVisibility(View.GONE) 没有删除我的 CustomTextView

android - 如何确定 TextView 中可见的行数?

android - 删除后 fragment 仍然存在吗?

android - 使用 Jitpack 构建库 Github 包括依赖项

android - 带有 TextView 和按钮的 MapFragment 在单独的 UI 段中

android - 如何从 recyclerview 适配器类更改主要 Activity 中的 textview 文本

android - getString(int resId, Object... formatArgs) 方法中参数的样式文本

android - 图像字节流操作

Android 对象动画不能正常工作

android - 返回时如何刷新 fragment UI