问题
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!!!
回答1:
By default, subclasses of ViewAnimator
will adjust size to their largest children.
To avoid this, try adding android:measureAllChildren="false"
to your TextSwitcher
来源:https://stackoverflow.com/questions/15620310/android-textswitcher-couldnt-wrap-content-width-after-set-text