I have a TextView whose text can run to many lines. Once it has been created and set dynamically, I\'d like to
If I understand correctly the answer to question 2 is:
textView.getLineBounds (int line, Rect bounds)
The width in pixels should be abs(bounds.right - bounds.left)
; and the height is abs(bounds.bottom - bounds.top)
Your first question is a bit more tricky, but something like this should do the required magic:
Layout layout = textView.getLayout();
String text = textView.getText().toString();
int start=0;
int end;
for (int i=0; i<textView.getLineCount(); i++) {
end = layout.getLineEnd(i);
line[i] = text.substring(start,end);
start = end;
}
For the First question:
The previous selected answer didn't make the cut for me as my textview had word wrap. Use the following line to get the text from the given line number 'i'
Kotlin:
var textofline:String = textview.text.subSequence(textview.layout.getLineStart(i), textview.layout.getLineEnd(i)).toString()
Let me know if it is lacking explanation.
PS: I'm no master in android. Just sharing my knowledge in case someone finds it useful