重置Android TextView Maxlines [英] Reset Android textview maxlines

查看:48
本文介绍了重置Android TextView Maxlines的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个可以通过用户触摸折叠的TextView.当TextView折叠时,我设置了 textView.setMaxLines(4); .如何在我的expand方法中清除此状态?我只能想到用 10000 之类的大数值调用 setMaxLines().

I want to make 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);
        }
       }
     }

您可以在Android开放源代码项目(AOSP)的源代码中找到它

You can find this in the source code of Android Open Source Project (AOSP)

https://source.android.com/source/downloading

如果您不想下载源代码,则可以在github上的类似镜像上查看源代码.

If you do not want to download the source, you can view the source on a mirror like this one at github.

https://github.com.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java

这篇关于重置Android TextView Maxlines的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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