我正在通过 appcompat 库使用 Android 自动调整大小的 TextView,如下所示:
<android.support.v7.widget.AppCompatTextView
android:id="@+id/info"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:maxLines="1"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="8sp"
app:autoSizeMaxTextSize="14sp"
app:autoSizeStepGranularity="0.5sp"
android:text="@string/something" />
这在第一次设置文本时效果很好 - 例如,如果需要,文本大小会缩小。
但第二次设置时,如果内容足够小,文本大小不会再次增长。它保持适合先前内容的较小尺寸。
那么,在自动调整大小的 TextView 上调用 setText
的正确过程是什么,以便遵守自动调整大小的参数?或者有没有办法强制 TextView 重新评估其内容并调整文本大小?
我尝试在调用 setText
之前将文本大小设置回默认值,但这似乎没有效果。
最佳答案
通过重现您的代码,我遇到了同样的问题,唯一可行的解决方案是为 TextView 提供特定高度,例如:android:layout_height="30dp"
来自:https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview#setting-textview-autosize < br/>
If you set autosizing in an XML file, it is not recommended to use the value "wrap_content" for the layout_width or layout_height attributes of a TextView. It may produce unexpected results.
关于android - 自动调整 TextView 的大小不适合更新的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51995471/