Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android "Roboto Light" pixelation

I'm including the Roboto family of fonts in my application, and create the fonts in code like so:

Typeface robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");

I have noticed that certain smaller sizes (even the suggested sizes from the Android Developer Typography page) appear distorted or pixelated. Here is a screenshot of a few TextViews in the app:

roboto_pixelated

"Upcoming Dates" uses a larger size and looks fine. The other ones are sized at 14sp and look awful. The problem is not with margin or padding in the TextViews -- I've tried altering both. Does anyone know what causes this problem, and how to fix it?

like image 465
mhouglum Avatar asked Aug 14 '13 16:08

mhouglum


1 Answers

Try the following on each of your TextViews with the custom typeface:

int flags = textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG
            | Paint.ANTI_ALIAS_FLAG;
textView.setPaintFlags(flags);
like image 154
Karakuri Avatar answered Nov 13 '22 08:11

Karakuri