Autosizing of TextView doesn't work (Android O) Autosizing of TextView doesn't work (Android O) android android

Autosizing of TextView doesn't work (Android O)


Additional to the other correct answers I found another point which prevents autosizing to work.

Do not use android:singleLine="true" together with autosizing. Use the newer android:maxLines="1" instead.


I have tested this for a few situations, and have the below conclusion:

You must have bounded width and height. For example, if you set width to be match_parent but wrap_content for height, I think Android doesn't know that how high you want to stretch your text. In your example you don't have a specific height, so I think that's why it doesn't work.

For example:

wrap content height for a text

specific height for a text

I don't know why Android official document would use wrap_content as an example...

And as you can see I didn't use other attributes in my example, so it probably is not the problem of incorrect attributes.

And, yes, the TextView I am using is android.support.v7.widget.AppCompatTextView.

And as long as you are using support library 26.0.0 or above it is good enough.

EDIT:

As for ConstraintLayout, the principal is the same. You should have both bounded width and height, which means either one of below for each dimension:

  1. You have specified an absolute value for that dimension (width or height)

  2. You have set Constraint to both directions

For example:

All 4 directions are constrainedHeight set to be an absolute valueWidth set to be an absolute value

UPDATE: (2017-09-21)

I have tested that unfortunately it seems it does not support custom typeface yet, which is a function published together in support library v26...


I had the same issue.I solved it by changing two lines in my gradle:compile 'com.android.support:support-v4:26.0.1' and compile 'com.android.support:appcompat-v7:26.0.1'To fit longer texts you have to add all four options, like this:

<android.support.v7.widget.AppCompatTextView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:text="@string/your_string"        app:autoSizeTextType="uniform"        app:autoSizeMaxTextSize="13sp"        app:autoSizeMinTextSize="5sp"        app:autoSizeStepGranularity="1sp"/>