0

I have a dimen.xml defined in values folder

<dimen name="dimen_button_border_width">2dp</dimen>
<dimen name="version_txt_size">14sp</dimen>

How if I need to add dimen for different values folder like mdpi,hdpi,xxhdpi . What happens to the value of 2dp& 14sp in corresponding folders. Is there any mathematical formula ?

Devrath
  • 42,072
  • 54
  • 195
  • 297

2 Answers2

1

check out what these units are in here

in short: 1dp (density pixel) means 1*density_factor in px, no matter of folder

so 1dp on mdpi device is 1px, on xxhdpi device is 3*1px and so on

you don't need to put same integer in different qualifying folders, it will be calculated same way. but you may when you want e.g. bigger space on low-res devices (different value)

for example - you have thick line separator, very thin, height is 0.5dp. on xxxhdpi device it will be 0.5 x 4 = 2px. but same value for mdpi device will be 0.5 x 1 = 0px (because of int rounding) and your thick separator is gone... in this case you may put in values-mdpi and values-hdpi (1.5 factor) folders different, fixed value in px already instead of dp (in above example it should be 1px overriding 0.5dp -> 0px)

snachmsm
  • 17,866
  • 3
  • 32
  • 74
0

How if I need to add dimen for different values folder like mdpi,hdpi,xxhdpi

You do not need to add dimension resources for different density-based resource sets.

What happens to the value of 2dp& 14sp in corresponding folders. Is there any mathematical formula ?

14sp is the same in all densities. 2dp is the same in all densities. So, the mathematical formula is equality.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491