设置文本后,Android TextSwitcher无法换行内容宽度 [英] Android TextSwitcher couldn't wrap content width after set text

查看:130
本文介绍了设置文本后,Android TextSwitcher无法换行内容宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TextSwitcher淡入-设置文本时淡出动画.但是在更改文本时,按内容的宽度来包装内容时会遇到一些问题.

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.

以下是我的TextSwitched xml:

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>

我有一个字符串列表,每当我从长词更改时,例如从"Hello World"到"World",textswitcher不会包装字符串"World"的宽度,而是保留"Hello World"一词的宽度.

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.

请提出建议!

推荐答案

默认情况下, ViewAnimator 的子类将调整其最大子级的大小.

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

为避免这种情况,请尝试将 android:measureAllChildren ="false" 添加到您的 TextSwitcher

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

这篇关于设置文本后,Android TextSwitcher无法换行内容宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆