Android: Font size can't be larger than 717px in a text box on any device

1k views Asked by At

I wanted that a certain fraction of my screen should have a digit. But while working on that I had a problem that, for certain screens the text was not being displayed and the logcat showed -> Font size too large to fit in cache. While working to solve the problem I tried certain codes and found that whenever the text size was larger than 717 pixels the logcat showed that error.

So, I wanted to know whats the rule for this. Can we not have text size greater than 717 pixels on any device in android ?

Tested on MOTO G phone, Nexus 5 emulator

I tried this to test

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>

Now when android:textSize was 717 px "1" was displayed on the screen but when I did 718px or above I got the error -> Font size too large to fit in cache. width, height = 170, 511.

What does this error mean ?

Text box height is large enough to have 1 of 717px as following are the dimensions of the devices on which I tested the code and text box is match_parent

Nexus 5 -> screen dimensions 1080*1920 px

Moto g -> screen dimensions 720*1280 px

1

There are 1 answers

4
M S Gadag On BEST ANSWER

try like this..

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

and add this too..n try

urtextview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

reference: Font size too large to fit in cache