1

I am testing on Samsung galaxy tab 3 with dimensions are 1024 by 600. size is 7 inches.

i created following folders.

drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi

i checked dpi of my device using this link http://dpi.lv/#1024×600

My device have 170 dpi(dots per inch).

when i run my project. Image in drawable-mdpi folder is triggered by my device.

I took following image from tutorial i am following.

enter image description here

According to tutorial image is fetched from correct folder i.e drawable-mdpi (2. Medium Density)

Now my question is:

With regards to size Android have four categories of devices. small, normal, large, xlarge

Lets take large size category. (my 7 inches device comes under large size) Large size category can be of any from following types.

1) large size with 100 to 130 dpi(dots per inch)

2) large size with 120 to 180 dpi(dots per inch)

3) large size with 180 to 280 dpi(dots per inch)

4) large size with 280 to 360 dpi(dots per inch)

It is ok. android will trigger images from corresponding drawable-<--dpi> folders. But we have kept different size images in all drawable-<--dpi> folders.

As in my case i kept small size image in drawable-mdpi.But my tablet screen size is 7 inches.

so it is triggering image from drawable-mdpi. which is very small for a 7 inches screen.

what is correct way to use it. do i have to create folder like :

drawable-large-mdpi
drawable-large-ldpi
drawable-large-hdpi
drawable-large-xhdpi 

and so on.

Please explain this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
vabhi vab
  • 419
  • 4
  • 11
  • You either need to be more explicit with your question, or need to rephrase it. From what I'm reading you seem to be asking for a complete tutorial on how to do multiple sizes, which is way too broad a question. – Gabe Sechan Mar 19 '16 at 08:40
  • This might help you http://stackoverflow.com/questions/35506714/what-package-to-download-for-material-design-icons/35508728#35508728 – Eugen Pechanec Mar 19 '16 at 09:22
  • my question is different from this answer. plz read my question and try to answer. i am confuser with this from a long time. – vabhi vab Mar 19 '16 at 09:27

1 Answers1

3

The idea is that you have one image but different sizes for each folder. mdpi is the base where 1 pixel = 1 dp (density pixel). Say you have an ImageView that is 48dpx x 48dp, at mdpi that image will be 48x48 pixels and you will put it into drawable-mdpi. Then you create scaled versions of that image for each of the other folders, hdpi is 1.5x the size of mdpi, so you would scale the image to 72x72 pixels which would equate to 48dp by 48dp for hdpi devices.

After you've put one image in each folder (they have to be named the same) Android will handle the rest when you reference the image as R.drawable.image, it will calculate the devices density and then retrieve the right image for that devices density.

Check out this existing answer for more information image size (drawable-hdpi/ldpi/mdpi/xhdpi)

Edit: To answer your most recent edit, this may be where you consider having different sizes for phones and tablets (based on screen width). For phones you might have the image at 48dp x 48dp but for tablets you might set it to 96dp x 96dp. The best way to do this would be to utilise dimension resources. You should already have a values package, you can create a 2nd values package named values-sw600dp, sw600dp means that devices with a screen width of 600dp or more will get their values from this package. Then create a dimens.xml in your values-sw600dp folder (and in your values folder if you don't already have one). Then add a dimension to each respective dimens.xml file like so: <dimen name="image_size">48dp</dimen> and <dimen name="image_size">96dp</dimen>. For larger devices your image will be larger to compensate for the extra screen real estate, for smaller devices the image size will remain the same. This way the image size will be relative to the devices density independent screen width. Does that help?

Community
  • 1
  • 1
Dom
  • 8,222
  • 2
  • 15
  • 19
  • you mean that image will be of one size imagine : 144 by 144. In my layouts i will give static width and height throuth values-swdp to 96 , 96 and 48, 48 so on ? – vabhi vab Mar 19 '16 at 09:38
  • You would set those values in the `dimens.xml` file and then in your layout file you would set the ImageViews dimensions like so `layout_width="@dimen/image_size"` and do the same for height. The actual image file itself would need to match the largest dimension at mdpi level, so if you had 144 and 96 as your large and small values your image would have to be 144x144 at mdpi so that it doesn't get pixelated. – Dom Mar 19 '16 at 09:43
  • ok, if i have 144 by 144 as my largest image requirement. i will keep 144 size image in my drawable-mdpi folder. Then what will be the size of same image inside drawable-hdpi, drawable-xhdpi, drawable-xxhdpi etc. – vabhi vab Mar 19 '16 at 09:50
  • if 144 is answer. then what is the difference between drawable-mdpi drawable-hdpi, drawable-xhdpi, drawable-xxhdpi ? – vabhi vab Mar 19 '16 at 09:51
  • mdpi = 1 times (144), hdpi = 1.5 x mdpi (144 * 1.5 = 216), xhdpi = 2 x mdpi (144 * 2 = 288), xxhdpi = 3 x mdpi (144 * 3 = 432). Does that make sense? – Dom Mar 19 '16 at 09:55
  • ok..., plz read my comments and let me know did i understand everything correctly ? i added images in all folders as to tell me in you last comment. – vabhi vab Mar 19 '16 at 10:25
  • i created values-swdp and i mentioned all dimensions in these files Eg. dimes for all sizes of tablet and phones etc. and set them in my layout.xml files. – vabhi vab Mar 19 '16 at 10:26
  • Now whenever a device (Tablet or phone) with 100 to 130 dpi(dots per inch) will come. then images will be triggered form drawable-ldpi. when a device (tablet or phone) with 120 to 180 dpi will come then images will be triggered form drawables-mdpi and so on. – vabhi vab Mar 19 '16 at 10:27
  • is there only benefit that images will not get pixelate in with different dpi ? – vabhi vab Mar 19 '16 at 10:27
  • Yep it sounds like you understand it. Yes that is the reason for having the different dpi drawable folders is because the images need to be scaled to suit the devices density, if you only had one image at mdpi size, if an xxhdpi device used it, it would have to scale that image up to 3x its size which would look terrible. Have you had the chance to test it yet? If you only have a tablet available you can use emulators to test the different screen sizes. – Dom Mar 19 '16 at 10:36
  • thanks bro, one last ques, as per your last comment. if i want to add three buttons i my app. Then first thing i will do is : -> observe those image sizes on a mdpi. and let the size according to my largest device with mdpi is "x". and now i create same images as following. – vabhi vab Mar 19 '16 at 13:07
  • mdpi = 1 times (144), hdpi = 1.5 x mdpi (144 * 1.5 = 216), xhdpi = 2 x mdpi (144 * 2 = 288), xxhdpi = 3 x mdpi (144 * 3 = 432). Does that make sense? – vabhi vab Mar 19 '16 at 13:07
  • And use them. if Yes. The layout preview we see in android studio is mdpi ? if No. then how can test in mdpi. ? – vabhi vab Mar 19 '16 at 13:09
  • If by largest device you mean largest dimension (in dp) then yep that sounds right. In Android Studio you can create Virtual Devices, check out this link to see how to get to the Android Virtual Device Manager http://developer.android.com/tools/devices/index.html Once you find the AVD Manager you can create emulators for specific densities such as mdpi – Dom Mar 19 '16 at 23:22
  • Thanks i got the concept. :)) – vabhi vab Mar 20 '16 at 15:25