简体   繁体   English

Android TextView字幕

[英]Android TextView marquee

I'd like to shorten the text out if it's too long and add "..." at end. 如果文本太长,我想缩短文本,并在末尾添加“ ...”。 This is the example where I would like to clip the text: 这是我要剪切文本的示例:

在此处输入图片说明

I've tried multiple variations of code (TruncateAt.END, .setLines(4), ...) but I think this should work: 我已经尝试了多种代码变体(TruncateAt.END,.setLines(4),...),但是我认为这应该可行:

textv.setMaxLines(4);
textv.setEllipsize(TruncateAt.MARQUEE);

But the result is this: 但是结果是这样的:

在此处输入图片说明

What is wrong? 怎么了?

You can get the substring of the string, and use that as the max length, and add the ... at the end. 您可以获取字符串的子字符串,并将其用作最大长度,并在末尾添加...。

int MAX_LENGTH=40;
if(inString.length > MAX_LENGTH)
    View.setText(inString.subString(0,MAX_LENGTH) + "...";

I hope this will help you out... 我希望这可以帮助您...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM