Android "Roboto Light" pixelation - android

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:
"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?

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

Related

TT-Chocolates font not rendering properly in small sizes

I've started using the font TT-Chocolates font in an Android app, but with font sizes < 16sp the font is being rendered uneven/inconsistently (e.g. TT-Chocolates-Regular 14sp, full resolution screenshot taken with android studio 1080x2400 Poco X3):
As you can see e.g. the "r" letters is drawn differently in two different textviews (list of elements with the exact same style and font size). In iOS, with the same size this problem does not occur.
Any thoughts? Thank you very much in advance!

Android Monospace doesn't behave as a fixed-pitch

As you can see in the screenshot below the two different strings with the same length not drawn with the same width on the canvas. I'm using a monospaced typeface, so isn't it promised to be drawn with the same width? Is that because of the kerning?
Typeface.create(Typeface.MONOSPACE,Typeface.NORMAL)
This is a well-known kerning issue with monosapce font on Android. It looks like this is a quite old topic.
Some people have already faced this problem:
Android Monospace fonts aren't fixed width - 2013-06-11
Are Android monospace fonts actually fixed size? - 2016-06-22
Android monospace space ( ) width is different than character width - 2017-03-02
The issue also occurred in mobile web environment:
Font monospace Android 2.3 - 2013-07-11
where problem explained with missing glyph:
https://github.com/googlefonts/noto-fonts/issues/617
Solutions:
Option 1.:
Looking for an alternative fixed-width font might be the easiest way. Some helpful links to find one:
https://1stwebdesigner.com/free-monospaced-fonts/
https://www.fontsquirrel.com/ https://www.dafont.com/
https://www.urbanfonts.com/free-fonts.htm
https://www.1001freefonts.com/
Option 2.:
You can override text drawing using Spans. This post may help you:
https://stackoverflow.com/a/53452941/5823014
Option 3.:
You can modify the monospace font file to fix kerning. This online tool can be useful:
http://www.glyphrstudio.com/online/

Varying font sizes when using different .ttf fonts with no change to the sp

Problem: When implementing a custom font I notice quite a big change in the font size. (Without any altering to the font size in the XML file)
This is causing a significant variation between the Actual font size in comparison to the size shown in the Graphical layout in ADT. (Visually about 20sp smaller)
I am building a timer application and want to use a Digital Looking font.
Question: Can a .ttf file affect the font size relative to a constant 'sp' ?
To answer my own question.
YES. a .ttf file does have a 'base font size' and this may vary from one .ttf to another.
As stated in my comment above:
I figured out how to change the base size of a .ttf using FontForge (fontforge.org) There is a great tutorial on how to do this here: forum.xda-developers.com/showthread.php?t=990853 I did have to play around with more options then noted in the tutorial to get my font just right but it works perfect!

trouble with font size for different screen size/resolution

I know this has been answered in other questions, but nothing is working for me. I have a text view where I want the text to appear the same size in a variety of density/screen size combinations. I have tried specifying
android:textSize="30dp"
and
android:textSize="30sp"
and have also used
TextView text = (TextView) findViewById(R.id.text);
text.setTextSize(30 * (getResources().getDisplayMetrics().density));
30 is my font size *****
the text doesn't scale properly. It becomes way too small at lower densities and as screen size increases. Are there additional techniques I can use to scale my font?
create layout-large, layout-small, layout-xlarge etc.. versions of your layout xml file.
You can set the size differently in each so that the font will look right across a variety of screen sizes.
After years of constantly having everything slightly off on different devices, I recently discovered that the inches and cm measurements for dimensions are literally that.
So even on devices where 160dp isn't quite an inch, specifying 1inch will give exactly that, on everything, even if they have a custom scaled ROM.
I now specify anything I want very tight control over with these.
If you just want to have separate font sizes for separate screens, you can create dimens in your value.xml for sw600dp and sw720dp folder too and put different values there. You don't need to create separate xml layout for each, if you just need to change font sizes.

Best way to set text size?

What is the best way to set the text size so it looks the same on all devices? The biggest problem I am having is setting the text size on the buttons so everything fits or isn't too small. I have tried setting the size in the xml, and I have just tried setting it dynamically by getting the screen size and messing with the screen width and height to set the size. I had tested different things on different devices and thought all was well, until I just tried my app on the Galaxy Nexus and half of my words were getting chopped off inside of the button. I made some adjustments and the font is now way too small on tablets.
Using the xml has worked fine for me before, but most of these new 7" tablets use the large layout, so my images and text are really small if I set the height, width, and text size with the xml. Setting the widths and hights dynamically have helped with the buttons and image sizes, but the font still doesn't look quite right.
Is my best bet just to find a happy medium via xml(large, x-large, etc.) or are there other ways?
Have you seen this article: Supporting Multiple Screens ?
It says:
you should prefer the sp (scale-independent pixel) to define text
sizes. The sp scale factor depends on a user setting and the system
scales the size the same as it does for dp.
The same issue is explained here, Different text size for different hardware

Categories

Resources