我正在寻找一种方法,当我更改屏幕大小时,它将按比例调整文本大小 . 目前我尝试了Auto Scale TextView Text to Fit within Bounds但它确实没有确定我是否以正确的方式做到了 . 我现在正在打电话
AutoResizeTextView test = new AutoResizeTextView(this);
test=(AutoResizeTextView)findViewById(R.id.test456);
test.resizeText(); // I call this to resize.. am I right?
XML
<com.mypackage.AutoResizeTextView
android:id="@+id/test456"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
3 回答
好消息! Google在Android O中引入了Autosizing TextView支持 . 它也将包含在支持库中 .
https://developer.android.com/preview/features/autosizing-textview.html
您不需要调用
AutoResizeTextView test
,因为类扩展TextView
,您可以说TextView
. 我也不需要拨打resizeText()
.无论哪种方式,这是我喜欢用于自动重新调整文本大小的自定义类 .
我使用它,按比例在屏幕的宽度 .
CONST是我用来缩放字体的数字,在我想要的尺寸中 . 它适合我的需要 .