Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roboto inconsistent font height

I'm currently facing strange problems with Android's font Roboto. At first I had two TextViews in one horizontal LinearLayout, centered both vertically and horizontally. The first TextView was set font Roboto-Black.ttf and the second was Roboto-Light.ttf. Both was set to textSize="12sp", but the one with Roboto-Light.ttf was just a pixel higher then the Roboto-Black.ttf TextView. But it didn't happen when I've set textSize="13sp". So I've created new Android project, just to be sure it's not only in the one application. The result is almost identical, but in this case, textSize="12sp" works as expected but textSize="13sp" doesn't. I've made screenshots to show the issue.

12sp works as expected. Top edges align. image

13sp has this strange behavior. image

Strange is, that this happens only when I try to mix thin and thick lined variants. When I make one TextView Roboto-Bold.ttf and second Roboto-Black.ttf, result is good. When I try Roboto-Light.ttf and Roboto-Thin.ttf, it also work properly.

So I also tried to test this in photoshop and this is what I found:

image

It's the same for all fonts from Roboto family, except for the Roboto-Light.ttf. I can also post source code for the layout if needed.

Thanks in advance.

PS: I'm sorry for the links but due to low reputation (brand new account) I can't post images. Also in the last link i had to remove the "h" from "http", because it didn't allow me more than two links.

like image 845
Tadeas Kriz Avatar asked Aug 19 '12 21:08

Tadeas Kriz


1 Answers

I can't tell you if its the fonts or how your phone interprets the fonts and displays them on the screen but I can tell you that I've had issues with centering views in the middle before.

Have you tried using a relativelayout and then align the second textviews top and bot with the first textview? That might solve the problem.

like image 57
Warpzit Avatar answered Nov 03 '22 16:11

Warpzit