21

Android allows us to define hdpi/mdpi/ldpi for the drawable folder in order to account for different sized screens/devices. I was wondering if that same support can be applied for the Values folder (or even the layout folder)? Reason being, I typically define a "sizes.xml" file which holds standard dp sizes that I apply to margins and paddings. I also do the same for sp sizes for text. I'd like to adjust those values based on the phones dpi.

Ifrit
  • 6,791
  • 8
  • 50
  • 79

4 Answers4

34

Yes, you can. Just like this:

res/values/dimens.xml(default)
res/values-ldpi/dimens.xml   (240x320 and nearer resolution)
res/values-mdpi/dimens.xml   (320x480 and nearer resolution)
res/values-hdpi/dimens.xml   (480x800, 540x960 and nearer resolution)
res/values-xhdpi/dimens.xml  (720x1280 - Samsung S3, Micromax Canvas HD, etc) 
res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
res/values-large/dimens.xml  (480x800)

res/values-large-mdpi/dimens.xml (600x1024)
res/values-sw600dp/dimens.xml  (600x1024)
res/values-sw720dp/dimens.xml  (800x1280)
res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
res/values-large-xhdpi/dimens.xml  (1200x1920 - Nexus 7"(latest))

(from: http://wiki.jikexueyuan.com/project/android-actual-combat-skills/multi-resolution-adapting-common-directory.html Warning: the link is chinese!!! To translate, right click on the page, click "translate to English" in the popup menu.)

Kai Wang
  • 3,303
  • 1
  • 31
  • 27
26

Yes, I believe anything in the res/ folder can use "Configuration Qualifiers". So for example, you can have a values-sw600dp-mdpi-land/ folder.

See "Using Configuration Qualifiers": http://developer.android.com/guide/practices/screens_support.html#qualifiers

I first noticed this by looking at Google's IOSched app sample code, look at the res folder: https://github.com/google/iosched/tree/master/android/src/main/res

You'll see that they have "values-sw600dp-land", "values-w400dp" and "values-v17" folders, just to name a few.

Sam Dozor
  • 40,335
  • 6
  • 42
  • 42
3

As values folders are more suitable to use for setting different margins and font sizes based on device resolution, though some hdpi devices takes values from values-xhdpi. So instead using values-normal-hdpi, values-normal-xhdpi is more appropriate answer.

By using this, we can also omit need of different layout folders by setting different dps and sizes in values folders to support phones and tablets very easily.

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
Mihir Shah
  • 1,799
  • 3
  • 29
  • 49
0

Yes, you can define files to be used based on whatever the standard modifiers are. For instance, in one of my apps I have defined styles.xml and strings.xml files for various sizes and orientations and it all works as expected values-large-hdpi and values-large-land-hdpi, etc.

MattC
  • 12,285
  • 10
  • 54
  • 78