Android 设置TextView自动调整字体大小
意为:TextView字体大小随着控件的大小变化而变化,Android 8.0(API26)新增,但兼容库 com.android.support:appcompat-v7:26.0.0版本以上已完全兼容到 API14
android_auto_size.gif
有三种设置方式:
默认
粒度
预设大小
1.默认
允许TextView在水平轴和垂直轴上均匀地自动调整刻度。
1.1.原生设置
xml设置
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform" />
代码设置
// 参数: int autoSizeTextType
textView.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM);
1.2.兼容库设置
xml设置
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="unif