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/
Related
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!
Okay, this is driving me nuts. I've been troubleshooting a formatting issue and have been stripping and stripping the code down and no explanation for what I see.
Look at the following page:
http://test.solivitahoa.com/testbig.php
VERY simple HTML. No CSS, no JS, just a table with 2 columns. If you view it on your desktop, it's fine and looks as expected. HOWEVER, if you view it in Chrome on Android (I'm running Android 8 on OnePlus 5), the first cell has text that is much smaller than the right cell even though there is no sizes specified in the code.
The formatting is as expected until the last "1234567890" is set on the first line and then it increases the font size.
What causes this? Is there a way around it?
That is od. One way to fix it is to set a fixed text size on the whole document. For example, this css fixes the issue:
body {
font-size: 12px;
}
You can consider this your font reset css.
I have set a linear layout as 32 dp in sketch app using mac and when the same dimesnsions implemented in android studio and then i took the screen shot and imported to sketch app and when compared with the sketch designed measurements there was a huge difference in the height i.e the height was 44dp so can some help me out in this how to match exact measurements from sketch to android layouts.
I have faced this problem many times and found this solution which worked for me
In sketch first use the art-board which fits material design
for eg: 360 x 640
Get you design fit in height can vary and than try to export your design using zeplin, creat your android project using zeplin and export all your screens, zeplin will help you telling exact font, font size, images size also it allows to copy xml to be used in android studio and this give almost perfect result only difference while comparing is android bottom buttons and screens you need to adjust manually
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!
I'm working on a Android project where I need to build my layouts based on a JSON layout file. This same file is also being used on an iOS app. So there is 1 file which will render the same layout on the Android as well as on the iOS.
The JSON layout file defines its font sizes based on the default iOS font unit.
From the Android docs:
Points - 1/72 of an inch based on the physical size of the screen.
And as far as I can find, iOS font sizes are also defined as 1/72 of an inch.
So based on this info, I'd say the following should be enough:
view.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSizeInIosUnit)
This however results in the text being too large. And it also seems to differ per device (which is weird since points should always appear in the same physical size).
If you want fonts to resize properly according to screen size you should use dp/dip instead.
So try this instead:
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSizeInIosUnit);
Now this might not be exacly the same but in my experience this gives the best results. If it doesn't have the proper size then figure out what size you need on Android as the base size and then go with that instead.