Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have TextView scale its font size to fill parent?

Tags:

android

Is there a way to have a TextView pick a font size such that it fills whatever space it has available? For example:

<LinearLayout
  layout_width="fill_parent"
  layout_height="50dip" >

  <TextView
    layout_width="fill_parent"
    layout_height="fill_parent"
    textSize="scale?" />

</LinearLayout>

Thanks

like image 387
user291701 Avatar asked Jan 27 '11 21:01

user291701


2 Answers

No, there is not built in font scaling in a TextView. You could overload the onDraw() method in a child of TextView, but TextView does not support scaling the text automatically.

Take a look at this other question.

like image 181
Nick Campion Avatar answered Nov 09 '22 20:11

Nick Campion


Just to update, from API 26 (Android 8.0) TextViews has an attribute to scale text on horizontal and vertical axes

<?xml version="1.0" encoding="utf-8"?>
<TextView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:autoSizeTextType="uniform" />

Check it at Autosizing TextViews

like image 36
Lorenzo Vincenzi Avatar answered Nov 09 '22 20:11

Lorenzo Vincenzi