Search code examples
androidscreenscreen-resolution

Achieving the same font size in different screens ratio


I'm using a library in Android that with a given size, it creates dynamically a font.

Before, I used to calculate the font sizes taking as a reference the width of the screen so it was always using percents of the width, using the following formula: x/100*screenWidth

What happens with this? That if the screen has a different ratio (relation between width and height) this solution is not accurated because it will adapt to the width but not to the height...

I'm a bit lost trying to find a solution for a new formula that take into account both width and height. Any idea? Really thanks!


Solution

  • What about a percentage of (screenWidth + screenHeight)/2 ?