23

So i recently switched to android 3.0 (honeycomb) and i'm having some issues with hardware rendering, specifically at a certain custom view i've written where I use a font size of 200 to display some text.

Unfortunately it seems the openGLRenderer doesn't like that kind of rather large font sizes very much, given the error i'm getting in the log:

06-06 16:22:00.080: ERROR/OpenGLRenderer(2503): Font size to large to fit in cache. width, height = 97, 145

Are there ways around this (or ways to fix it) such that I can get the text displayed at the wanted font size?

MrJre
  • 7,082
  • 7
  • 53
  • 66
  • So I've worked around it by creating images for all of the characters I need in that font size, but I can imagine there are times when you don't want to do such a thing, so keeping it open for a more definitive answer. – MrJre Jun 21 '11 at 13:20

3 Answers3

33

It is really a bug in the Android OS inside the Hardware Acceleration modules. I think that the best way is to ask the system to avoid HW acceleration on TextViews that contain large size text. To do so, just add in the code:

TextView bigText = (TextView) findViewById(R.id.bigtext);
bigText.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Shaish81
  • 331
  • 3
  • 4
  • 1
    This is the easy solution and works if you are using a TextView; I didn't use this, because using textfields my view hierarchy became to deep and to expensive to render and layout at the time. Instead I made a custom view and draw the text on the canvas myself. – MrJre Oct 24 '12 at 07:33
  • 1
    +1 i had large text disappearing on me and took me a while to figure out it was a hardware acceleration issue. this worked for me but i dropped the override right into the xml: android:layerType="software" – ggenglish Mar 14 '13 at 19:53
  • 7
    Unfortunately this doesn't seem to work anymore on 4.4 (meaning: I don't see the error anymore, but the text is not drawn). – BoD Mar 30 '14 at 17:42
  • 1
    using the xml version of this solved it for me in Android 6.0.1 – Someone Somewhere Aug 14 '16 at 22:39
  • I tried this work-around on another phone and one font doesn't show. However, on my tablet it *does* show. Is there a better work-around that's more reliable ? – Someone Somewhere Aug 16 '16 at 19:30
  • Do you have a reference to this bug in the Android bug database? – Stefan Haustein Nov 19 '17 at 23:14
8

Just an idea: Perhaps you can convert the font to an outline using Paint.getTextPath(...) and use this path to render the text. This should allow you to resize the path as needed.

Stefan Mücke
  • 823
  • 7
  • 12
4

The setLayerType method is useful, but unfortunately it is supported just for API >= 11. Developing for API = 8 or less it will become unusable.

If you can, a simple solution is disabling the hardware acceleration just for the activity that is giving you problems. I had this very problem and solved it this way:

<application
    android:...
    android:hardwareAccelerated="true" >
    <activity ...>
        ...
    </activity>

    <activity
        ...
        android:hardwareAccelerated="false">
        ...
    </activity>
</application>

This solution will disable the hardware acceleration just for the activities where you do not need it and where you aren't able to display large texts.

marzapower
  • 5,531
  • 7
  • 38
  • 76
  • 2
    with API 8 or less, there is no hardware acceleration, so there is no need for any of it. android:hardwareAccelerated only works API 11 and up. See also http://developer.android.com/guide/topics/graphics/hardware-accel.html – MrJre Oct 24 '12 at 07:26
  • I am developing an application that must run on API 8 but requires API 11 for Admob. So, I have to find a way to solve the problem using only public APIs that are available from API v. 8 on. And this approach fixes the problem. – marzapower Oct 26 '12 at 13:03