【问题标题】:Android: Font size can't be larger than 717px in a text box on any deviceAndroid:任何设备上的文本框中的字体大小不能大于 717px
【发布时间】:2015-02-23 01:06:32
【问题描述】:

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

所以,我想知道规则是什么。 android 的任何设备上的文本大小都不能超过 717 像素吗?

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

我试过这个来测试

Java

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 px 时,屏幕上显示“1”,但当我执行 718px 或更高时,我收到错误 -> 字体太大而无法放入缓存。宽度、高度 = 170、511。

这个错误是什么意思?

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

Nexus 5 -> 屏幕尺寸 1080*1920 像素

Moto g -> 屏幕尺寸 720*1280 像素

【问题讨论】:

  • 由于神奇的数字:717px而来到这个问题。我正在研究与打印纸尺寸相匹配的 CSS 媒体查询。在 Chrome 中,717 像素的宽度相当于一张 A4 纸的宽度。 483px 似乎是 Chrome 中 A5 纸的宽度,顺便说一句。

标签: android text fonts font-size text-size


【解决方案1】:

像这样尝试..

<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);

参考: Font size too large to fit in cache

【讨论】:

  • 相同的场景在 718px 及以上的情况下不起作用
  • 是的,感谢它现在的工作。但这是什么。请解释!
  • 非常感谢。我从 2 天开始就一直在研究这个
猜你喜欢
  • 1970-01-01
  • 2016-09-19
  • 2016-05-25
  • 1970-01-01
  • 2020-03-01
  • 2014-02-10
  • 2014-10-09
  • 2013-06-18
  • 2015-10-29
相关资源
最近更新 更多