Android控件篇 TextView限制文字长度且超过显示省略号

一、ellipsize

 <!-- Where to ellipsize text. 在哪里省略文本 -->
    <attr name="ellipsize">
        <enum name="none" value="0" />
        <enum name="start" value="1" />
        <enum name="middle" value="2" />
        <enum name="end" value="3" />
        <enum name="marquee" value="4" />
    </attr>

二、maxEms

 <!-- 使 TextView 最多有这么多 em 宽 -->
 <!-- Makes the TextView be at most this many ems wide. -->
        <attr name="maxEms" format="integer" min="0" />

三、singleLine

<!-- Constrains the text to a single horizontally scrolling line
     instead of letting it wrap onto multiple lines, and advances
     focus instead of inserting a newline when you press the
     enter key.

     The default value is false (multi-line wrapped text mode) for non-editable text, but if
     you specify any value for inputType, the default is true (single-line input field mode).

     {@deprecated This attribute is deprecated. Use <code>maxLines</code> instead to change
     the layout of a static text, and use the <code>textMultiLine</code> flag in the
     inputType attribute instead for editable text views (if both singleLine and inputType
     are supplied, the inputType flags will override the value of singleLine). } -->


     <attr name="singleLine" format="boolean" />

在这里插入图片描述

四、maxLength

<!-- 设置输入过滤器以将文本长度限制为指定数字 -->
<!-- Set an input filter to constrain the text length to the specified number. -->
        <attr name="maxLength" format="integer" min="0" />

五、使用

 <androidx.appcompat.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end" 
        android:maxLength="10"
        android:maxEms="10"
        android:singleLine="true"
        android:text="欢迎关注彭老希,硬核干货持续更新!" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

其子昱舟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值