0

I am making an Android application for multiple screen device. I want to know what should be the text size scale ratio for different density device?

example : if my text size is 28sp on mdpi device then what should be on hdpi device?

I made values-ldpi, values-mdpi, values-hdpi etc. and define text size in dimens of each respective values folder, but it did not look similar on all device.

Mike Marshall
  • 7,788
  • 4
  • 39
  • 63
rakrin
  • 1
  • 1
  • Check out this answer: http://stackoverflow.com/a/7107974/2282538 – Tyler Jan 22 '14 at 18:24
  • Hello Ravind, Thanks for quick reply. but if baseline in mdpi and text size for mdpi is 28sp then in hdpi = 42sp xhdpi = 56sp xxhdpi = 58sp which will seen very huge on respective density device – rakrin Jan 22 '14 at 18:50

2 Answers2

1

You dont need to know the ratios, and you shouldnt directly use them since the amount of densities keep changin.

If you use it in the resources, using the sp unit will do it work fine in every density, without diferent value folders.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="type1">28sp</dimen>
</resources>

If you do it from code, probably it will look diferent depending on howyou asign the values. You have to send the correct values to the setTextSizeFunction, for example:

setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.type1));
//he documentation method that COMPLEX_UNIT_PX returns a Resource dimension value multiplied by the appropriate metric.

or with hardcoded numbers:

setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
  • 3
    Are you sure about this? I have my text sizes in the values folder (sp) but they look tiny on xxxhdpi screens, so I have to uses different values folders and now I need to find a good ratio. – RED_ Nov 23 '15 at 15:37
0

Use below formula for declaration in dimens.xml

base mdpi= 1X

HDPI= 1.5X

XHDPI=2.0X

XXHDP=2.75X

above formula for relation b/W all Resolution

Ravind Maurya
  • 977
  • 15
  • 24
  • Hello Ravind, Thanks for quick reply. but if baseline in mdpi and text size for mdpi is 28sp then in hdpi = 42sp xhdpi = 56sp xxhdpi = 58sp which will seen very huge on respective density device – rakrin Jan 23 '14 at 05:50