Skip to content Skip to sidebar Skip to footer

What Should Be The Text Size Ratio In Android For Multiple Density Device?

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 28

Solution 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><dimenname="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);

Solution 2:

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

Post a Comment for "What Should Be The Text Size Ratio In Android For Multiple Density Device?"