0

Possible Duplicate:
How to adjust text font size to fit textview

hello,

I have a TextView that can have big or small word one word or few.

I went the size of the text to adjust itself to take all the space of the TextView

Like when the text its short so the size of the text will be big and when the text its long the size will be small.

Thanks for helping!!

Community
  • 1
  • 1
bifko
  • 41
  • 1
  • 2

1 Answers1

0

You will need to test for the string length then size accordingly. Here is an example of how I did it:

RemoteViews views = new RemoteViews(context.getPackageName(),
            R.layout.widget);
views.setTextViewText(R.id.message, message);
views.setFloat(R.id.message, "setTextSize", 12); //default size - required
if (message.length() > 90) {
    views.setFloat(R.id.message, "setTextSize", 9);
}

In my situation I only had two cases to worry about but if you need to constantly adjust your textSize you probably can make the value a function that returns a float based on the message length.

Robert Harvey
  • 168,684
  • 43
  • 314
  • 475
Woodsy
  • 2,708
  • 2
  • 22
  • 44