开发者

Animating TextView with custom font causes heavy work to font cache

I have a TextView for which i register the following animation:

mScaleAnimation = new ScaleAnimation(1f, 1.2f, 1f, 1.2f,
            mReferenceTextView.getWidth() / 2, mReferenceTextView
                    .getHeight() / 2);
    mScaleAnimation.setRepeatCount(Animation.INFINITE);
    mScaleAnimation.setRepeatMode(Animation.REVERSE);
    mScaleAnimation.setDuration(500);

It works fine and looks really cool :)

My only concern is the following: When i look at logcat, it is totally unusable since as long as the animation ist running, i keep getting these logs over and over multiple times a second :(

06-20 17:50:05.5开发者_JS百科55: DEBUG/skia(14179): purging 213K from font cache [7 entries]
06-20 17:50:05.750: DEBUG/skia(14179): purging 196K from font cache [7 entries]
06-20 17:50:05.870: DEBUG/skia(14179): purging 202K from font cache [8 entries]
06-20 17:50:05.995: DEBUG/skia(14179): purging 190K from font cache [8 entries]

The TextView uses a custom font/typeface (which is in otf format).

Any ideas what causes that heavy work for the font cache?


I believe that your cache is getting killed because you are generating tons of TypeFace objects. I'm guessing that this is on a pre ICS release? There is a bug that holds TypeFaces and does not free it up correctly. So when your animating, it keeps creating new objects for each position and they are leaked and never cleaned up.

I found someone's suggestion to create a TypeFace cache with a HashMap. You can check this post out for more details. Custom fonts and XML layouts (Android)


If you're constantly changing the actual font size, Both Skia and HWUI will be constantly re rasterising and recaching new glyphs of the right size. Memory usage can grow very quickly and performance will nosedive. You shouldn't get this issue if you're just scaling the canvas, but then you wont get the quality either.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜