编程方式创建的TextView用省略号省略号、方式、TextView

由网友(距离只有三公分)分享简介:我编程方式创建,我想省略号结尾一个TextView。I'm programmatically creating a TextView that I want to ellipsis at the end.伪code:tv.setEllipsize(TextUtils.TruncateAt.END);tv.setHo...

我编程方式创建,我想省略号结尾一个TextView。

I'm programmatically creating a TextView that I want to ellipsis at the end.

伪code:

    tv.setEllipsize(TextUtils.TruncateAt.END);
    tv.setHorizontallyScrolling(false);
    tv.setSingleLine();

以上的伟大工程。

The above works GREAT.

    tv.setEllipsize(TextUtils.TruncateAt.END);
    tv.setHorizontallyScrolling(false);
    tv.setMaxLines(1);

这是行不通的。这是一个错误?我不明白为什么我不能让文字在椭圆时指定MAXLINES尤其是1 MAXLINE但setSingleLine是确定结束。

This does not work. Is this a bug? I don't understand why I can't get text to ellipses at the end when specifying maxLines especially a maxLine of 1 but setSingleLine is ok.

推荐答案

setSingleLine() setSingleLine(真) $ P $更改其高度更行pvents TextView的和强制的TextView忽略换行符( ñ字符串中的符号)。

setSingleLine() or setSingleLine(true) prevents the TextView from changing its height to more lines and forces the TextView to ignore line breaks (the symbol n in a string).

setMaxLines(INT N)显示在TextView中显示的字符串这是由一个换行符分开的第一n行。

setMaxLines(int n) displays the first n lines of the String displayed in the TextView which are separated by a line break.

例如让字符串是我的第一行 n和我的第二线 n和第三个

For example let the String be "my first line n and my second line n and a third one"

setSingleLine()让TextView中显示我的第一行和我的。由于显示宽度超过了和 setMaxLines(1)结果我的第一行 setMaxLines(2)结果的行话说的我的第一行及以下和我的第二行 setMaxLines(3)显然不会对这个样本串任何影响。 setSingleLine() lets the TextView display "my first line and my.." since the display width is exceeded and setMaxLines(1) results in "my first line" setMaxLines(2) results in "my first line" and below a line saying "and my second line" setMaxLines(3) obviously does not have any effect on this sample string.

更新:这应该工作setDoubleLine用截断:

Update: This should work for "setDoubleLine with truncation":

// optional: string.replace("n",""); or string.replace("n"," ");
tv.setSingleLine(false);
tv.setEllipsize(TextUtils.TruncateAt.END);
int n = 2; // the exact number of lines you want to display
tv.setLines(n);
阅读全文

相关推荐

最新文章