我可以限制TextView的字符数吗? [英] Can I limit TextView's number of characters?

查看:58
本文介绍了我可以限制TextView的字符数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在拥有的是TextView元素的ListView.每个TextView元素都显示一个文本(文本长度从12个单词到100+个变化).我要使这些TextView显示一部分文本(比如说20个字或大约170个字符).

What I have now is a ListView of TextView elements. each TextView element displays a text (the text length varies from 12 words to 100+). What I want is to make these TextViews display a portion of the text (let's say 20 word or roughly 170 chars).

如何将TextView限制为固定数量的字符?

How to limit the TextView to a fixed number of characters?

推荐答案

这里是一个示例.我使用maxLength属性限制大小,使用maxLines属性将其限制为单行,然后使用ellipsize = end自动在已截断的任何行的末尾添加"...".

Here is an example. I limit the sizewith the maxLength attribute, limit it to a single line with maxLines attribute, then use the ellipsize=end to add a "..." automatically to the end of any line that has been cut-off.

<TextView 
    android:id="@+id/secondLineTextView" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:maxLines="1" 
    android:maxLength="10" 
    android:ellipsize="end"/>

这篇关于我可以限制TextView的字符数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆