So I have a TextView in android that has the width of the whole length of the screen and a padding of dip 5. How can I calculate the number of characters that will fit a si
Try this:
private boolean isTooLarge (TextView text, String newText) {
float textWidth = text.getPaint().measureText(newText);
return (textWidth >= text.getMeasuredWidth ());
}
Detecting how many characters fit will be impossible due to the variable width of the characters. The above function will test if a particular string will fit or not in the TextView. The content of newText should be all the characters in a particular line. If true, then start a new line (and using a new string to pass as parameter).
Answer to the comment:
str.size()>numCol
vs is too large? You will need to implement your animation (hint #1: insert a newline character)setText
). (hint #3: Keep track of the lines created with a static int lines;
and use newString.split("\\r?\\n")[lines-1]
to check for length).