Is there a way to hide text in a TextView?

前端 未结 7 2293
清歌不尽
清歌不尽 2021-02-08 13:09

Is there a way to hide some (but not all) of the text in a TextView? I tried setting the size to 0 with AbsoluteSizeSpan, but that doesn\'t have any visual effect that I see.

7条回答
  •  离开以前
    2021-02-08 13:37

    I just had this problem and wrote the following class:

    public class NoDisplaySpan extends ReplacementSpan {
    
        public NoDisplaySpan() {}
    
        @Override
        public void draw(Canvas arg0, CharSequence arg1, int arg2, int arg3,
                float arg4, int arg5, int arg6, int arg7, Paint arg8) {}
    
        @Override
        public int getSize(Paint paint, CharSequence text, int start, int end,
                FontMetricsInt fm) {
            return 0;
        }
    }
    

    It seems to only work within a paragraph; I get an ArrayIndexOutofBoundsException thrown when I set the span to extend past a newline. I'd love to hear if anyone can figure that out.

提交回复
热议问题