Search code examples
androidautosizeandroid-textview-autosize

autoSizeText isn't displaying properly


I've got a layout that utilizes a table with a couple of rows. I'm attempting to use the API 26 autoTextSize functionality to ensure the text stays on a single line. The issue that I'm having is with the text being cut in half on first display in my list. If I scroll down the list, the text is fine, and then when I come back up to the top of the list my text is fine, but when it first displays it is cut in half. Here's the code I'm using for auto sizing.

<TableLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_centerInParent="true"
                    android:gravity="center">

                    <TableRow
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:minHeight="30dp"
                        android:gravity="center">

                        <TextView
                            android:id="@+id/AITAsymbol"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:autoSizeMaxTextSize="30dp"
                            android:autoSizeMinTextSize="24dp"
                            android:autoSizeStepGranularity="2dp"
                            android:autoSizeTextType="uniform"
                            android:textAlignment="center"
                            android:textColor="#000000" />
                    </TableRow>

                    <TableRow
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:gravity="center">

                        <TextView
                            android:id="@+id/received"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textAlignment="center"
                            android:textColor="#ffffff" />
                    </TableRow>
                </TableLayout>

Am I missing something with regards to how I should be using the auto sizing feature in Android?Half text display


Solution

  • You need to keep either layout_width or layout_height fixed for the Auto Text Sizing property to work.