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 o开发者_Python百科f 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!!
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.
精彩评论