Android TextSwitcher couldn't wrap content width after set text

只愿长相守 提交于 2021-02-07 11:57:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!