2

Can someone please post an example how to use this class? I use it directly in my xml and didn't work.

<LinearLayout
                        android:id="@+id/button_30_days_plan"
                        android:layout_width="match_parent"
                        android:layout_height="60dp"
                        android:layout_gravity="center"
                        android:layout_marginBottom="20dp"
                        android:background="@color/primary"
                        android:padding="10dp">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:layout_weight="0"
                            android:maxLines="1"
                            android:text="@string/monthly_plan_title"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="@color/white" />

                        <mycompany.mobile.core.ui.AutoResizeTextView
                            android:id="@+id/price_30_days_plan"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="end"
                            android:maxLines="1"
                            android:layout_gravity="center_vertical"
                            android:text="@string/monthly_plan_cost"
                            android:textColor="@color/white"
                            android:textSize="24sp"
                            android:textStyle="bold" />
                    </LinearLayout>

The AutoResizeTextView should use the remaining LinearLayout width and resize if the width is not enough. In another part of the code it seem works perfectly, and it just reference the id in the java code without setting anything regarding with AutoResizeTextView class.

<-- This is works -->
            <LinearLayout
                android:id="@+id/layout_start"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/StartIcon"
                android:layout_alignTop="@+id/StartIcon"
                android:layout_toLeftOf="@+id/ReverseButton"
                android:gravity="center_vertical"
                android:layout_toRightOf="@+id/StartIcon"
                android:orientation="vertical">

                <mycompany.mobile.core.ui.AutoResizeTextView
                    android:id="@+id/StartLabel"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:maxLines="1"
                    android:text="@string/direction_click_here_label"
                    android:textColor="#001485"
                    android:textSize="15sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/TapToChangeStartLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tap to change destination"
                    android:textColor="#001485"
                    android:layout_marginTop="-3dp"
                    android:visibility="gone"
                    android:textSize="12sp" />
            </LinearLayout>

I tried call setMinTextSize() and setMaxTextSize() after checking the text length and still didn't work. Any help please.

Community
  • 1
  • 1
Seto
  • 1,234
  • 1
  • 17
  • 33

1 Answers1

0

For someone who stumbled upon this post, the solution is to call resizeText() after setting the text.

Seto
  • 1,234
  • 1
  • 17
  • 33