如何以编程方式禁用TextView maxLines? [英] How to disable the TextView maxLines programmatically?

查看:65
本文介绍了如何以编程方式禁用TextView maxLines?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难以编程方式重置 TextView maxLines 属性.

I'm having a hard time reseting the maxLines attribute of a TextView programmatically.

只需尝试将其设置为 0 ,它将无法正常工作. -1 使应用程序崩溃.我可以使用一种更简单的解决方法,将 maxLines 设置为 5000 ,但是我不想这样做.

Just tried setting to 0 and it doesn't work. -1 crashes the application. I could use a simpler workaround and set the maxLines to 5000 but I don't want to do that.

有什么想法怎么做?

更新

好吧,我发现了一个问题.我也设置了Ellipsize ...我将使用以下解决方法:

Well, I've found one problem.. I've set the Ellipsize as well... I'm just going to use the following workaround:

TextView questionDetail = (TextView) mQuestionDetailHeader.findViewById(R.id.desc);

questionDetail.setText(mCurrentQuestion.getQuestion());
questionDetail.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode
questionDetail.setEllipsize(null);

推荐答案

由于尚未获得批准的答案-重置TextView的maxlines属性的正确方法是:

As there isn't yet an approved answer - the proper way to reset the maxlines property of the TextView is:

textView.setMaxLines(Integer.MAX_VALUE);

根据 Valdemar 的评论以及此

As per Valdemar's comment and this stackoverflow answer. Using -1 will cause an ArrayIndexOutOfBoundsException.

请紧记 END MARQEE setEllipsize()设置,对于 = 2的maxlines会受到尊重,这取决于

Keep in mind only END and MARQEE setEllipsize() settings will be respected for maxlines >= 2 according to the documentation:

如果已使用setMaxLines(int)设置两行或更多行,则END和仅支持MARQUEE *(其他省略号类型不支持任何东西).

If setMaxLines(int) has been used to set two or more lines, END and MARQUEE* are only supported (other ellipsizing types will not do anything).

这篇关于如何以编程方式禁用TextView maxLines?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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