How to get text size of each line in StaticLayout that span is applied for each line?

282 views Asked by At

I have a StaticLayout that AbsoluteSizeSpan is applied for each line. How to get size of lines in this layout?

1

There are 1 answers

0
Mojtaba jalambadani On

try this

private int charPerLine(TextView textView){
    String s = "";
    for (int i = 0; i <= 1000; i++) {
        s+="X";
        if(isTooLarge(textView,s)){
            return i;
        }
    }
    return 1000;
}

private boolean isTooLarge (TextView textView, String text) {
    float textWidth = textView.getPaint().measureText(text);
    return (textWidth >= textView.getMeasuredWidth ());
}