附加到 TextView 时自动调整大小不起作用 Android

Autosizing not working when appending to TextView Android

所以我正在制作一个简单的计算器应用程序,我需要让文本视图中的数字在到达其边缘时自动调整大小。现在,如果我使用 TextView.setText(TextView.getText()+"5") 它自动调整没问题,但为了简单起见我喜欢使用 TextView.append("5") 。但是,当使用追加功能时,TextView 调整大小似乎不会更新并且根本不会调整文本大小。

我试过使用 API 26 级调整大小和 post 26 级调整大小。 前 API 级 26 大小调整示例:

        android:layout_height="60dp"
        app:autoSizeTextType="uniform"
        app:autoSizeMinTextSize="12sp"
        app:autoSizeMaxTextSize="100sp"
        app:autoSizeStepGranularity="2sp"

有人知道我该怎么做吗?还是我一直在使用 TextView.setText(TextView.getText()+"5")? 提前致谢!

很遗憾,我认为您将不得不返回 TextView.setText(TextView.getText()+"5")。这是我的推理:

TextView.append() 定义为:

Convenience method to append the specified text to the TextView's display buffer, upgrading it to TextView.BufferType.EDITABLE if it was not already editable.

将缓冲区类型更改为 TextView.BufferType.EDITABLE 会将 TextView 带入 EditText 的领域(EditText 扩展 TextView) 并且 EditText 不支持自动调整大小:

来自documentation for EditText

This widget does not support auto-sizing text.