dimens.xml in values folder for 7" and 10" tablet, how to?

Joserra picture Joserra · May 17, 2012 · Viewed 14.6k times · Source

I have tried with:

values-mpdi, values-land-mpdi, values-hpdi and values-land-hdpi

which works fine in phone's screens, the problem is that it could happen that a 7" tablet takes the value from values-mdpi and a 10" tablet too, but the result is not the same, I guess because of the screen size (although is the same resolution and similar density) so I tried:

values-sw600dp-hdpi
values-sw600dp-port-hdpi
values-sw600dp-mdpi
values-sw600dp-port-mdpi
values-sw720dp-hdpi
values-sw720dp-port-hdpi
values-sw720dp-mdpi
values-sw720dp-port-mdpi

but the app crashes because it does not find the resource needed....

any help will be much appreciated

thanks in advance

Answer

Ritesh Gune picture Ritesh Gune · Jun 25, 2014

Basically three main device categories exist that Android applications need to support:

  1. handsets (phones)
  2. small tablets (7″ category)
  3. large tablets (10″ and above).

Qualifiers before Android 3.2:

Google’s first attempt at creating qualifiers to separate resources by device was to create a handful of size buckets: small, normal, large, xlarge. Initially, this worked out well as handset devices were in the small/normal category, the first 7″ tablets on the market were large, and the first 10″ tablets were xlarge.

Qualifiers with Android 3.2 onwards:

However, as more and more devices began appearing in the market with new screen sizes and the lines began to blur about where a device might present itself. A new solution to the problem was presented in Android 3.2, in the form of new qualifiers to pick resources based on a devices current width/height or “smallest” width; the latter being a new designation for the devices size by representing it in terms of the width (in density-independent pixels, or dp) of the shortest side of the screen.

Using the new paradigm, it has become common to define small tablets as having a smallest width of 600dp, and large tablets at 720dp, with handsets being everything that falls below that line.

Using qualifiers when minimum support is below 3.2 and target is higher than or equal to 3.2 For applications targeting Android 3.2 or higher as a minimum this new system works well. However, if developers wishing to create an application that runs universal on handsets and tablets are compelled to support a minimum Android version no higher than 2.2, or at best 2.3, then in that case create duplicates of each resource in a directory with the old size qualifier and place it an another directory with a corresponding smallest width qualifier.

E.g. keeping the same dimens.xml file in values-large and values-sw600dp. So the device running on android version lower than 3.2 will take values from values-large and the device running on android version higher than or equal to 3.2 will take values from values-sw600dp