安卓:在任何设备上的文本框中,字体大小都不能大于 717 像素



我希望屏幕的某个部分应该有一个数字。但是在处理这个问题时,我遇到了一个问题,对于某些屏幕,文本没有显示,并且logcat显示->字体大小太大而无法放入缓存。在努力解决问题时,我尝试了某些代码,发现每当文本大小大于 717 像素时,logcat 都会显示该错误。

所以,我想知道这个规则是什么。我们可以在安卓的任何设备上都有大于 717 像素的文本大小吗?

在MOTO G手机上测试,Nexus 5模拟器

我试过这个来测试

爪哇岛

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

.XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent">

   <TextView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="1"
        android:textSize="717px"/>
</RelativeLayout>

现在,当android:textSize为717像素时,屏幕上显示"1",但是当我执行718px或更高时,我收到错误->字体太大而无法放入缓存。 宽度,高度 = 170, 511。

这个错误是什么意思?

文本框高度足够大,可以有 1 个 717px,因为以下是我测试代码和文本框的设备的尺寸match_parent

Nexus 5 ->屏幕尺寸 1080*1920 px

Moto g ->屏幕尺寸 720*1280 px

尝试这样做。

<TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="1"
            android:textSize="717px"/>

并添加这个..n 尝试

urtextview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

参考:字体太大,无法放入缓存

相关内容

最新更新