Issue
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.
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.
Solution
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?
Answered By - Dom

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.