Debopam Mitra
Debopam Mitra

Reputation: 1870

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!!!

Upvotes: 14

Views: 2478

Answers (1)

Bloodkite
Bloodkite

Reputation: 431

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

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

Upvotes: 39

Related Questions