问题描述
我很难以编程方式重置 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 的评论以及此.使用-1将导致 ArrayIndexOutOfBoundsException
.
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:
这篇关于如何以编程方式禁用TextView maxLines?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!