Android 8.0开始提供自动调整TextView的大小功能,官方链接: developer.android.com/guide/topic…
不过在使用时有两个问题需要注意:
1.不能设置android:singleLine="true",如果有需求必须使用android:maxLines="1"
2.TextView宽高必须指定,不可设置wrap_content,要么具体数值,要么match_parent
一般写法如下:
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp" />