Android 8.0 provides automatic adjustment function of the size of the TextView, official link: developer.android.com/guide/topic…

However, there are two problems to pay attention to when using:

1. Do not set Android :singleLine=”true”, if necessary must use Android :maxLines=”1″

2. The width and height of the TextView must be specified. You cannot set wrap_content, either a specific value or match_parent

It is generally written as follows:

<TextView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:autoSizeTextType="uniform"
    android:autoSizeMinTextSize="12sp"
    android:autoSizeMaxTextSize="100sp"
    android:autoSizeStepGranularity="2sp" />
Copy the code