Any idea why AppCompatTextView (AndroidX) with autoSizeTextType is not working in Tablets and Compat theme?

634 views Asked by At

I have been trying to add autosize to my app but it's failing. It never resizes the text. Here you have a preview where both Text View types (TextView and AppCompatTextView) and they look exactly after applying the required properties.

Nexus 10 with Android 11 in an Emulator

preview

preview measure

This is an image from a Huawei emulator:

hauwei

I tried the following combinations and all look exactly the same:

granulary 2sp

<!-- AppCompatTextView with android: option -->
<androidx.appcompat.widget.AppCompatTextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    android:autoSizeTextType="uniform"
    android:autoSizeMinTextSize="16sp"
    android:autoSizeMaxTextSize="100sp"
    android:autoSizeStepGranularity="2sp" />

<!-- AppCompatTextView with app: option -->
<androidx.appcompat.widget.AppCompatTextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    app:autoSizeTextType="uniform"
    app:autoSizeMinTextSize="16sp"
    app:autoSizeMaxTextSize="100sp"
    app:autoSizeStepGranularity="2sp" />

<!-- TextView with android: option -->
<TextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    android:autoSizeTextType="uniform"
    android:autoSizeMinTextSize="16sp"
    android:autoSizeMaxTextSize="100sp"
    android:autoSizeStepGranularity="2sp" />

<!-- TextView with app: option -->
<TextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    app:autoSizeTextType="uniform"
    app:autoSizeMinTextSize="16sp"
    app:autoSizeMaxTextSize="100sp"
    app:autoSizeStepGranularity="2sp" />

granulary 12sp

<!-- AppCompatTextView with android: option -->
<androidx.appcompat.widget.AppCompatTextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    android:autoSizeTextType="uniform"
    android:autoSizeMinTextSize="16sp"
    android:autoSizeMaxTextSize="100sp"
    android:autoSizeStepGranularity="12sp" />

<!-- AppCompatTextView with app: option -->
<androidx.appcompat.widget.AppCompatTextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    app:autoSizeTextType="uniform"
    app:autoSizeMinTextSize="16sp"
    app:autoSizeMaxTextSize="100sp"
    app:autoSizeStepGranularity="12sp" />

<!-- TextView with android: option -->
<TextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    android:autoSizeTextType="uniform"
    android:autoSizeMinTextSize="16sp"
    android:autoSizeMaxTextSize="100sp"
    android:autoSizeStepGranularity="12sp" />

<!-- TextView with app: option -->
<TextView
    android:text="@string/lblYourWeight"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:textStyle="bold"
    app:autoSizeTextType="uniform"
    app:autoSizeMinTextSize="16sp"
    app:autoSizeMaxTextSize="100sp"
    app:autoSizeStepGranularity="12sp" />

This is my latest code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="*"
            android:paddingTop="10dp"
            android:paddingBottom="5dp">
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatTextView
                    android:text="@string/lblYourWeight"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp" />
                <androidx.appcompat.widget.AppCompatTextView
                    android:text="@string/hUnits"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp" />
            </TableRow>
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatEditText
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:inputType="numberDecimal"
                    android:layout_column="0"
                    android:id="@+id/txtWeight" />
                <androidx.appcompat.widget.AppCompatSpinner
                    android:layout_column="1"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:id="@+id/spinnerWeightUnits" />
            </TableRow>
        </TableLayout>
        <androidx.appcompat.widget.AppCompatTextView
            android:text="@string/gUnits"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="16sp"
            android:autoSizeMaxTextSize="100sp"
            android:autoSizeStepGranularity="2sp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
        <androidx.appcompat.widget.AppCompatSpinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinnerUnits"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="16sp"
            android:autoSizeMaxTextSize="100sp"
            android:autoSizeStepGranularity="2sp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
                
        <TableLayout
            android:layout_weight="1"
            android:stretchColumns="2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dp"
            android:paddingBottom="5dp">
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatTextView
                    android:text="@string/lblFirstCelestial"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:layout_weight="1"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp" />
                <androidx.appcompat.widget.AppCompatTextView
                    android:text="@string/lblSecondCelestial"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textStyle="bold"
                    android:layout_weight="1"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp" />
            </TableRow>
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatSpinner
                    android:layout_column="0"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"
                    android:id="@+id/spinnerFirstCelestial" />
                <androidx.appcompat.widget.AppCompatSpinner
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"
                    android:id="@+id/spinnerSecondCelestial" />
            </TableRow>
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatImageView
                    android:adjustViewBounds="true"
                    android:layout_column="0"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:src="@drawable/earthp"
                    android:maxWidth="128dip"
                    android:id="@+id/imgFirstCelestial" />
                <androidx.appcompat.widget.AppCompatImageView
                    android:adjustViewBounds="true"
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:maxWidth="128dip"
                    android:layout_height="wrap_content"
                    android:src="@drawable/earthp"
                    android:id="@+id/imgSecondCelestial" />
            </TableRow>
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_column="0"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"
                    android:id="@+id/lblDFirstCelestial" />
                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"
                    android:id="@+id/lblDSecondCelestial" />
            </TableRow>
            <TableRow
                android:layout_height="wrap_content"
                android:layout_width="match_parent">
                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_column="0"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:gravity="center_horizontal"
                    android:layout_height="wrap_content"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"
                    android:id="@+id/lblGFirstCelestial" />
                <androidx.appcompat.widget.AppCompatTextView
                    android:layout_column="1"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:autoSizeTextType="uniform"
                    android:autoSizeMinTextSize="16sp"
                    android:autoSizeMaxTextSize="100sp"
                    android:autoSizeStepGranularity="2sp"                    
                    android:id="@+id/lblGSecondCelestial" />
            </TableRow>
        </TableLayout>
        <androidx.appcompat.widget.AppCompatTextView
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lblGDescription"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="16sp"
            android:autoSizeMaxTextSize="100sp"
            android:autoSizeStepGranularity="2sp"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
        <androidx.appcompat.widget.AppCompatTextView
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="16sp"
            android:autoSizeMaxTextSize="100sp"
            android:autoSizeStepGranularity="2sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:id="@+id/lblDWeight"
            android:paddingTop="10dp"
            android:paddingBottom="5dp" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:visibility="invisible" />
            <androidx.appcompat.widget.AppCompatImageView
                android:visibility="gone"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/imgWeight"
                android:paddingTop="10dp"
                android:maxWidth="256dip"
                android:adjustViewBounds="true"
                android:layout_weight="2" />
            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:visibility="invisible" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

My style is this one:

<style name="Theme.GNowTheme" parent="Theme.AppCompat">
    <item name="android:colorPrimary">#000000</item>
    <item name="android:colorPrimaryDark">#000000</item>
    <item name="android:textColor">#BEBEBE</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
</style>

You can check the app here (it's written in Xamarin.Android):

https://bitbucket.org/supernovaic/gnow-android/src/autosize/

Any idea what am I doing wrong? Thanks.

P.S.:

  • Any idea why the android:maxWidth="128dip" is not working also?
  • I'm testing in a Nexus 10 with Android 11 in an Emulator.
  • I don't have a physical tablet to test.
0

There are 0 answers