-3

I have a lack of experience in developing android apps. I've decided to separate up dimensions.xml into 4 configuration qualifiers : default, sw480dp, sw600dp, sw800dp. Where can I see the quantity of android devices that have certain screen width in dp?

brut
  • 327
  • 1
  • 11
  • **1** This question doesn't meet our quality standards. **2** Why on Earth is it important to know `how many devices` have a certain density? **3** `4 configuration qualifiers : default, sw480dp, sw600dp, sw800dp.` and **default** is... ? – Phantômaxx Jul 25 '15 at 21:56
  • by default i mean less than 480dp. – brut Jul 25 '15 at 22:14
  • Always start with a single dimens file for all devices. If you have specific issues with specific values on specific screens, you may add exceptions to additional files. If you really want 2 completely different renderings, everything above sw600dp can be considered as a tablet, everything below as a phone. – BladeCoder Jul 25 '15 at 22:30
  • dp is loosely related to dimension. as an approximation 4"screen is ~320dp wide, 5" is 360, 7" is 600. – njzk2 Jul 25 '15 at 22:34

1 Answers1

0

There is no way to know how many devices have certain display aspects, you just have to support it, because it is possible to exist at least one device with that aspects.

Check this article, here you can find some informations you may looking for.

EDIT

You want to support multiple screen sizes, you could do as the following (I consider this the best aproach, I use it, it is very intuitive and I never get any colateral results, if anyone think this is not good, please let me know):

  • Your project contais a folder called values, inside it create a file called dimens.xml (can be anything, the name doesn't matters, it is just a convention) and then, inside, create something like this:

<dimen name="my_dimen">32dp</dimen>

  • 32dp will be your default dimen for all screen sizes. Here is an example for how to use it:

android:layout_width="@dimen/my_dimen"

  • Lets say you use the dimen you declared to represent some img size, 32dp may be good for small screens, but could be too tiny for bigger screens, you can create a separate file that will have different dimen values depending on the size of the user's screen, then the Android OS system will pick the best for you. Go to the res folder (the same folder where values folder is present) and than create a folder called values-hdpi, values-xhdpi, values-xxhdpi and so on.

  • Inside each folder, create the same dimens.xml file and on each file create the same <dimen name="my_dimen">xxdp</dimen>, where xx could be 40, 50, 100, 1000, you can set any value that could fit your requirements.

Here is an working example:

values >> dimens.xml

<dimen name="margin_big">21dp</dimen>

values-hdpi >> dimens.xml

<dimen name="margin_big">28dp</dimen>

values-xhdpi >> dimens.xml

<dimen name="margin_big">40dp</dimen>

...

How to use it:

<!-- rest of code -->
android:layout_margin="@dimen/margin_big"
<!-- rest of code -->

How this will work:

The article I posted tell us something about what is mdpi, hdpi, etc, lets say the Android determine some screen as hdpi, the OS will go to the values-hdpi and will look for a dimen called margin_big, he found it? Take its value and do whatever he have to do with it. OMG THERE IS NO margin_big INSIDE VALUES-XHDPI (lets imagine this is true), no problem, forget values-hdpi and go for values folder, this folders have to contains all default datas idependently of the screen size, if anything goes wrong android will look here for what he wants.

PLUS

values-pt = values for portuguese devices. values-jp = values for japonese devices and so on.

See this article for more information.

Murillo Ferreira
  • 1,423
  • 1
  • 16
  • 31
  • I've seen this article. Asked this question, because i don't know how to separate dimens.xml by the best way, to support most devices and create minimum dimens.xml. – brut Jul 25 '15 at 22:20
  • I want to support multi screens by using different configuration qualifiers by size. U think, that do it by using configuration qualifiers by density is better way? – brut Jul 25 '15 at 23:13
  • I think yes, because it is avaliable in all android versions, your way only work on android 3.2+ as you can see here: http://developer.android.com/intl/ru/guide/practices/screens_support.html#DeclaringTabletLayouts This should not be a problem, but when I was learning android, about 2+ years ago, most os devices was running 2.3.3 and android 4.x was starting to get space on the market, today this scenario is different, but anyway, doing this way never was a problem to me. You could use your approach if explicity necessary, of course. – Murillo Ferreira Jul 25 '15 at 23:22