For my Android game I have some calls to Canvas.drawText()
.
For testing, I use the standard font size which seems to be working fine.
However, w
The easiest way is to define your font sizes in your resources with the units of scale-independent pixels (sp
) -- this unit is like density independent pixels (dp
or dip
) in that it takes into account the screen density but it also takes into account the font-size setting of the user.
To add a new dimension create a dimens.xml
file in your res/values
folder and enter the following code to add a new dimension with the name myFontSize
:
20sp
You can then get the text size in your application using
int scaledSize = getResources().getDimensionPixelSize(R.dimen.myFontSize);
The resulting size will be correctly scaled to take into account the current screen density and font-size setting.
For more information see the Android Developers page on More Resources.