Reputation: 399
Let's say we have a large String and many textviews which all have maxLines="1"
and layout_width="match_parent"
and a monospaced font.
I need to know how many characters of my string I can put in a Textview
before it needs a new line.
It would be great if the solution could work with EditText
too.
Upvotes: 5
Views: 1923
Reputation: 6251
TextPaint paint = textView.getPaint();
int wordwidth=(int)paint.measureText("a",0,1);
int screenwidth = getResources().getDisplayMetrics().widthPixels;
int num = screenwidth/wordwidth
Upvotes: 4