首页 > 解决方案 > TextViewCompat 在文本视图自动调整大小期间不起作用(用于支持库)

问题描述

我知道,在我们应该使用TextView之前使用自动调整API 26TextViewCompat

我有这样的看法

<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);

但是,我的观点显示了点。 在此处输入图像描述

标签: androidtextviewautosize

解决方案


作为替代方案,您可以使用一个很棒的库 https://github.com/grantland/android-autofittextview


推荐阅读