Android中 TextView的省略

当文字超过TextView的宽度时, 用省略号代替

Java中设置:

tv.setSingleLine(true);

tv.setEllipsiz(TextUtils.TruncateAt.valueOf("END"));

xml中设置:

android:singleLine="true"

android:ellipsize="end"

所有属性详解

  • end:省略号在结尾
  • start:省略号在开头
  • middle:省略号在中间
  • marquee:跑马灯

需要配合显示行数的约束一起使用

android:singleLine="true"

或者

android:maxLines="1"

注意:

singleLine约束后的省略号在偏下

maxLines约束后的省略号居中

相关推荐
xiaopang1 小时前
RK3568 AOSP 编译与快速部署实战
android
码农coding2 小时前
android12 SystemUI之通知
android
summerkissyou19872 小时前
android - 性能 - Perfetto - cpu 分析教程及例子
android·性能
AFinalStone4 小时前
Android 7系统休眠唤醒(七)内核层—wakelock与autosleep机制
android·休眠唤醒
starvapour4 小时前
在关机键损坏的情况下让手机关机
android·adb·手机
AFinalStone5 小时前
Android 7系统休眠唤醒(八)内核层—Alarm定时唤醒与硬件唤醒源
android·电源管理·休眠唤醒
AFinalStone5 小时前
Android 7系统休眠唤醒(五)休眠全链路
android·电源管理·休眠唤醒
zzq77976 小时前
Android 风险识别机制实测:从录屏悬浮窗到远程控制的边界评估
android·安全·安卓·app加固·御盾安全
码云数智-园园6 小时前
MySQL 慢查询排查完整流程
android