android - TextViewCompat 在文本视图自动调整大小期间不起作用(用于支持库)
问题描述
我知道,在我们应该使用TextView
之前使用自动调整API 26
TextViewCompat
我有这样的看法
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_text"
android:layout_width="45dp"
android:textAlignment="center"
android:layout_height="@dimen/number_picker_text_height"
android:background="@color/accent"
app:customFontName="Fabriga-Light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center"
android:maxLines="1"
android:singleLine="true"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="36sp"
app:autoSizeMinTextSize="12sp"
app:autoSizeStepGranularity="6sp"
tools:text="223"/>
而这样的代码
TextViewCompat.setAutoSizeTextTypeWithDefaults(
tvValue, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(
tvValue, 12, 36, 6,
TypedValue.COMPLEX_UNIT_SP
);
int[] preset = new int[]{12, 18, 24, 30, 36};
TextViewCompat.setAutoSizeTextTypeUniformWithPresetSizes(tvValue, preset, TypedValue.COMPLEX_UNIT_SP);
解决方案
作为替代方案,您可以使用一个很棒的库 https://github.com/grantland/android-autofittextview
推荐阅读
- ios - 尽管遵循了推荐的设置,但仍无法将 Swift 代码导入到 Objective-C。手动桥接的可能性?
- anylogic - 在 AnyLogic 中手动转换代理并访问其 SelectOutputOut 类型的参数?
- r - 标签乱序(ggplot2)
- apache-kafka - 回调中的 Kafka 生产者未来元数据
- mysql - 加入表格时使用最近的日期作为缺失的日期
- php - 如何在彼此内部嵌套 2 个带有 foreach 循环的 SQL 语句
- android - BOARD_AVB_ENABLE 标志在哪里?(验证启动 Android (AVB))
- laravel - 用于从 https 中排除 POST 端点的 Laravel .htaccess 配置
- postgresql - Hibernate:将实体数组传递给 PostgreSql 函数
- javascript - 每次添加新规则时是否需要更改 Firebase 凭据?