如何重置Android的TextView的maxlines的?Android、TextView、maxlines

2023-09-05 05:22:30 作者:辞岁

我想要一个TextView是可折叠通过用户的接触。 当TextView的崩溃,我设置textview.setMaxLines(4); 如何清除我在我的扩展方法这种状态? 我只能想到电话setMaxLines()与价值一大批像10000。

I want a textview that is collapsable by user's touch. when the textview collapsed, I set textview.setMaxLines(4); how to I clear this state in my expand method? I can only think of call setMaxLines() with a value large number like 10000.

有没有实现这更好的方法呢?

Are there better ways to implement this?

感谢

推荐答案

其实,这样Android平台的确是由MAXLINE设置为Integer.MAX_VALUE。

Actually, the way android platform does that is by setting the MaxLine to Integer.MAX_VALUE.

textView.setMaxLines(Integer.MAX_VALUE);

此外,如果您使用的是Ellipsize,不要忘记设置为null。

also, if you are using Ellipsize, don't forget to set to null.

textView.setEllipsize(null);

只是检查如何Android框架做到这一点;)看setMaxLines(Integer.MAX_VALUE的);

just check how the android framework do just that ;) watch the setMaxLines(Integer.MAX_VALUE);

private void applySingleLine(boolean singleLine, boolean applyTransformation) {
    mSingleLine = singleLine;
    if (singleLine) {
        setLines(1);
        setHorizontallyScrolling(true);
        if (applyTransformation) {
            setTransformationMethod(SingleLineTransformationMethod.getInstance());
        }
       } else {
            setMaxLines(Integer.MAX_VALUE);
            setHorizontallyScrolling(false);
            if (applyTransformation) {
                 setTransformationMethod(null);
        }
       }
     }