I am using the following snippet in a code that checks if a string is small enough to fit inside a textview.
private int findLengthThatFits (TextView view, String text) {
float textWidth = view.getPaint().measureText(text);
if (textWidth >= view.getMeasuredWidth ()){
//do somethings
}
//other stuff
}
But view.getMeasuredWidth ()
keeps returning 0.0
. Does anyone know how I might fix this problem? I used How to find android TextView number of characters per line? as reference.