Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextSwitcher couldn't wrap content width after set text

I am using TextSwitcher to put fade in - fade out animation when I set text. But having some problems with wrapping the content by its width when the text is changed.

Following is my TextSwitched xml:

<TextSwitcher
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:layout_marginLeft="5dp"
                            android:layout_marginRight="5dp"
                            android:background="#ffffff"
                            android:paddingBottom="1dp"
                            android:paddingLeft="7dp"
                            android:paddingRight="10dp"
                            android:paddingTop="1dp" >

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:scrollHorizontally="true"
                                android:textAppearance="?android:attr/textAppearanceSmall"
                                android:textColor="@android:color/white" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:scrollHorizontally="true"
                                android:textAppearance="?android:attr/textAppearanceSmall"
                                android:textColor="@android:color/white" />
                        </TextSwitcher>

I have list of strings and when ever I change from long word e.g. "Hello World" to "World", the textswitcher does not wrap the width for the string "World", rather it keeps the width of the word of "Hello World".

In nutshell, the width remains fixed for the maximum width of the longest word.

Please suggest!!!

like image 893
Debopam Mitra Avatar asked Mar 25 '13 16:03

Debopam Mitra


Video Answer


1 Answers

By default, subclasses of ViewAnimator will adjust size to their largest children.

To avoid this, try adding android:measureAllChildren="false" to your TextSwitcher

like image 127
Bloodkite Avatar answered Sep 30 '22 04:09

Bloodkite