Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a textview that automatically changes it's font size to fit the space?

I am wondering how can I create or use if exists feature of TextView, to automatically change it's font size to fit the place.

Sometimes it should be larger if has space, and sometimes it should shrink in font size to fit the space.

What do you say?

like image 973
Pentium10 Avatar asked Dec 16 '10 15:12

Pentium10


People also ask

Which attribute increase or decrease the font size of TextView?

app:autoSizeMinTextSize=”10sp” using this attribute the TextView will be resized up to the size of 10sp and app:autoSizeStepGranularity=”2sp” using this attribute we are uniformly reducing the size of the TextView as 2sp when it goes out of the screen.

Which method is used to set the text in a TextView?

SetText(String, TextView+BufferType) Sets the text to be displayed using a string resource identifier.

What is autoSizeStepGranularity?

autoSizeMaxTextSize is the maximum size of textview it will take autoSizeMinTextSize is the minimum size of textview it will take and autoSizeStepGranularity is the size of each step.


1 Answers

you can change the font in your overrided version of

protected void onSizeChanged (int w, int h, int oldw, int oldh)

method.You need just to subclass TextView to do it.

Also, check this.

like image 111
Vladimir Ivanov Avatar answered Sep 18 '22 14:09

Vladimir Ivanov