I have a TextView with specific font and font size set. I want to determine if a multiline text will fit into this TextView (the TextView is set to match_parent for both width and height). Is there any reasonable way of doinf it?
Thanks
I have a TextView with specific font and font size set. I want to determine if a multiline text will fit into this TextView (the TextView is set to match_parent for both width and height). Is there any reasonable way of doinf it?
Thanks
You can measure the bounds of your text using this approach:
String yourText = "...";
Rect bound = new Rect();
textView.getPaint().getTextBounds(yourText , 0, yourText.length(), bounds);
Then you can get width and height of text for the giving textview:
bounds.width() or bounds.height();
If you put your TextView inside a ScrollView, you will know it will fit 100% :)
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Ty Juan" />
</ScrollView>