Textview - 最大长度不适用于椭圆

2024-02-27

我正在尝试创建一个文本视图,以便如果字符数超过 22,则显示省略号“...”会出现。然而,这不适用于 maxLength。


    <TextView
        android:id="@+id/vh_fragnotifications_postedby"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:layout_marginTop="8dp"
        android:text="zz12345678901234567890aaaaaaaa"
        app:layout_constraintTop_toBottomOf="@+id/vh_fragnotifications_body"
        app:layout_constraintLeft_toLeftOf="@+id/vh_fragnotifications_body"
        app:layout_constraintRight_toLeftOf="@+id/vh_fragnotifications_dateposted"
        android:maxLines="1"
        android:ellipsize="end"
        android:maxLength="22"/>

如何在保持最大数字 22 的情况下显示省略号?

这是完整的布局:___________________________________________________

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorWhite">

    <ImageView
        android:id="@+id/vh_fragnotifications_imagepreview"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignTop="@+id/vh_fragnotifications_body"
        android:layout_marginTop="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintVertical_bias="0"/>

    <TextView
        android:id="@+id/vh_fragnotifications_body"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        android:textColor="@color/colorBlackFont"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintLeft_toRightOf="@+id/vh_fragnotifications_imagepreview"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/vh_fragnotifications_imagepreview"/>

    <TextView
        android:id="@+id/vh_fragnotifications_postedby"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:layout_marginTop="8dp"
        android:text="zz12345678901234567890aaa"
        app:layout_constraintTop_toBottomOf="@+id/vh_fragnotifications_body"
        app:layout_constraintLeft_toLeftOf="@+id/vh_fragnotifications_body"
        app:layout_constraintRight_toLeftOf="@+id/vh_fragnotifications_dateposted"
        android:ellipsize="end"
        android:maxLength="22"
        android:maxLines="1"/>

    <TextView
        android:id="@+id/vh_fragnotifications_dateposted"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:layout_below="@+id/vh_fragnotifications_body"
        android:layout_marginTop="8dp"
        android:text=" • 18 hours ago"
        app:layout_constraintTop_toBottomOf="@+id/vh_fragnotifications_body"
        app:layout_constraintLeft_toRightOf="@+id/vh_fragnotifications_postedby"
        app:layout_constraintRight_toRightOf="@+id/vh_fragnotifications_body"
        android:maxLines="1"
        android:ellipsize="end" />


    <View
        android:id="@+id/vh_fragnotifications_divider"
        android:layout_width="0dp"
        android:layout_height="0.5dp"
        android:background="?android:attr/dividerVertical"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="@+id/vh_fragnotifications_body"
        app:layout_constraintRight_toRightOf="@+id/vh_fragnotifications_body"
        app:layout_constraintTop_toBottomOf="@+id/vh_fragnotifications_dateposted"/>


</androidx.constraintlayout.widget.ConstraintLayout>

Try this

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:layout_marginTop="8dp"
    android:text="zz12345678901234567890aaaaaaaa"
    android:maxLines="1"
    android:ellipsize="end"
    android:maxEms="11"
    />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Textview - 最大长度不适用于椭圆 的相关文章

  • 在android中通过BLE传输图像

    我使用以下代码传输 1 MB 的图像 如果在每个数据包之间实现线程延迟 则图像将成功传输 如果未设置线程延迟 则所有数据包均从BluetoothGattServer 发送 但BluetoothGattCallback 不会接收所有数据包 任
  • FTS3 在 ORMLite 中搜索?

    我对 FTS3 一无所知 除了http developer android com guide topics search search dialog html http developer android com guide topics
  • 带有一、二和三个按钮的 Android 警报对话框

    我不经常发出警报 但每次发出警报时 我都会花一些时间来阅读文档 https developer android com guide topics ui dialogs html并弄清楚如何去做 由于我现在不得不这样做几次 所以我将在下面写一
  • 从 Android 代码设置的 SECRET_CODE

    我知道如何使用清单文件中的秘密代码 它与此源代码配合良好
  • ffmpeg视频已压缩但无法在浏览器中播放

    我已经集成了ffmpeg4android lib 视频压缩工作正常 但视频无法在除 safari 浏览器之外的浏览器中播放 上传到服务器后 我使用了以下命令 ffmpeg y i
  • 使用 ADB 命令获取 IMEI 号码 Android 12

    对于 11 之前的 Android 版本 我使用以下命令从我的设备获取 IMEI 号码 adb shell service call iphonesubinfo 4 cut c 52 66 tr d space or adb shell s
  • 带操作按钮的颤动本地通知

    我在我的 flutter 项目中尝试了 flutter 本地通知插件 它在简单通知上工作正常 但我需要带有操作按钮的通知功能 请帮助我或建议我实现此功能 不幸的是 flutter local notifications 插件尚不支持操作按钮
  • 调试:在 Android 1.0 中找不到文件

    今天我更新到 Android Studio v 1 0 在尝试编译任何项目时出现以下错误 app build intermediates classes debug 找不到文件 问题是在更新之前我没有任何问题 这是我实际尝试编译的代码 构建
  • AudioTrack、SoundPool 或 MediaPlayer,我应该使用哪个?

    如果我需要能够 播放多个音频文件 具有不同的持续时间 例如 5 到 30 秒 独立设置右 左声道的音量 应用声音效果 如混响 失真 那么 我应该使用哪个 API 另外 我在 AudioTrack API 上找不到太多文档 有谁知道在哪里可以
  • Android onChange 事件未在 android 5 (Lollipop) 上的 chrome 历史记录的 contentObserver 中触发

    我注意到我的 chrome 历史记录和书签的 contentObservers 在 android lolipop 上不再触发 该代码在旧版本的 android 上完美运行 无论 chrome 版本如何 但在 Lollipop 上它不再运行
  • Android 应用程序中的 Eszett (ß)

    我的 res layout activity 文件中的德语 字符在我的应用程序中自动转换为 ss 即使我将语言和键盘设置为德语 它仍然不会显示 Android 中可以显示 吗 edit
  • 如何在 Android 模块中使用 FirebaseAuth

    我正在开发一个聊天库 我想在其中显示登录用户的对话 制作该库的原因是我想将其集成到多个项目中 我现在面临的问题是FirebaseAuth表示用户尚未登录 FirebaseAuth getInstance mFirebaseApp getCu
  • 菜单在片段的 onCreateOptionsMenu 处多次膨胀调用

    我使用 Fragments 当我切换到嵌套 Fragment 时 它实现了public void onCreateOptionsMenu Menu menu MenuInflater inflater 当我到达该嵌套片段时 我的菜单会多次膨
  • 使用 PhoneGap 使 Android 应用程序易于访问(对于残障人士)

    有人有过使用 PhoneGap 使 Android 应用程序可访问的经验吗 至少我们需要使我们的应用程序符合第 508 条规定 我尝试实现一些标准的辅助功能 文本框标签 向 div 添加标题属性等 但是 当在 Android 中使用 Tal
  • 在旋转时从错误的资源文件夹中提取可绘制对象

    在这里拉我的头发 因此 我正在使用一个具有多种类型的可绘制对象的应用程序 并且它们的结构如下 res Portrait resources drawable mdpi drawable hdpi drawable xhdpi Landsca
  • Android 后台服务示例,具有交互式调用方法

    我不是 Android 方面的专家 我正在寻找一个 Android 应用程序的示例 该应用程序使用一个服务 其中有真正的功能方法 或者换句话说 一个服务可以用来做什么 我们什么时候需要它 超越简单的东西服务举例 我确信您渴望获得一些工作代码
  • java.lang.NumberFormatException: Invalid int: "3546504756",这个错误是什么意思?

    我正在创建一个 Android 应用程序 并且正在从文本文件中读取一些坐标 我在用着Integer parseInt xCoordinateStringFromFile 将 X 坐标转换为整数 Y 坐标的转换方法相同 当我运行该应用程序时
  • 模块中的类无法加载

    我正在开发一个 2D Unity android 游戏 其中我最近添加了 Firebase Beta SDK 但添加后FirebaseAnalytics unitypackage我面临的错误是 无法加载模块中的类 当我删除文件夹时Fireb
  • 在Android Studio gradle项目中使用NDK和STL

    我在将 stlport 链接到 Android Studio 中的 gradle 项目时遇到问题 使用 NDK 的 Eclipse Android 项目迁移到 Android Studio 该项目使用 STL 我有包含内容的 android
  • Android 中带有组的列表视图

    我有一个列表视图 每行都有一些日期和文本 我可以像 iPhone 中那样将这个 listView 分组 组之间有标题吗 在 android 中是否可能 请帮忙 即 我需要在 Listview 行之间有标题栏 以便如果我使用日期对其进行分组

随机推荐