I am working on Android application that should support 2.1 till latest Android OS (4.2) version. Currently I have few images to display in my image-gallery module.
I need to support my app on all devices (smartphone and tablet) which support OS ranging from 2.1 to 4.2 (latest).
Each image is roughly of size 368X387, 50 KB each, PNG type
My workspace res contains following drawable folders:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xdpi
I have some confusion around
In which folder should I store the images, and how will that matter?
Do I need to have different resolution based images for different type of devices?
Thanks.
You can store images only in 1 folder BUT,
for example you have device that is mdpi.. it will look good on him, but if you run your app on ldpi android will automatically scale your image and it will look ugly (low quality). So yea you need different resolution based images for different types of devices..
so mdpi resolution images go to drawable-mdpi
so hdpi resolution images go to drawable-hdpi etcc..
this is some list i found on internet about screen sizes, maybe you will find it helpful:
Low density Small screens QVGA 240x320 (120dpi):
layout-small-ldpi (240x320)
layout-small-land-ldpi (320x240)
Low density Normal screens WVGA400 240x400 (x432) (120dpi):
layout-ldpi (240 x 400 )
layout-land-ldpi (400 x 240 )
Medium density Normal screens HVGA 320x480 (160dpi):
layout-mdpi (320 x 480 )
layout-land-mdpi (480 x 320 )
Medium density Large screens HVGA 320x480 (160dpi):
layout-large-mdpi (320 x 480 )
layout-large-land-mdpi (480 x 320)
Galaxy Tab ( 240 dpi ):
layout-large (600 x 1024)
layout-large-land (1024 x 600)
High density Normal screens WVGA800 480x800 (x854) (240 dpi):
layout-hdpi (480 x 800)
layout-land-hdpi (800 x 480)
Xoom (medium density large but 1280x800 res) (160 dpi):
layout-xlarge (800 x 1280)
layout-xlarge-land (1280 x 800)
Also it would be good to read official documents site about supporting different types of screen.
There are four folder in resource folder 1- drawable-hdpi 2-drawable-ldpi 3-drawable-mdpi
4-drawable-xdpi
To declare different layouts and bitmaps you'd like to use for different screens, you must place these alternative resources in separate directories/folders. This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
Then, place the files in the appropriate drawable resource directory: as per your need
if you want to use same images for all types of screen then you can make an other folder named "drawable" and put all images in that folder. it would work as default drawable.
but if you want to improve image quality on all resolutions. then you need all 4 types images and put then on their respective folder with same image name. you can also make differ XMLs for each resolution.
See this http://developer.android.com/training/multiscreen/screendensities.html
You can put a particular image in all folders.
drawable-hdpi
---->img.png
drawable-ldpi
---->img.png
drawable-mdpi
---->img.png
drawable-xdpi
---->img.png
It all depends on your os .it ll take by default according to device resolution .
In android we have "Res" folder is nothing but resources folder.Inside this res folder we have other sub folders but for storing images we have four types of folders names are called:
drawable-hdpi
for High density screens and its resolutions is 480*800
drawable-ldpi
for Low density screens and its resolutions is 240*320
drawable-mdpi
for Medium density screens and its resolutions is 320*480
drawable-xdpi
for Xtra density density screens and its resolutions is 640*960
If you want to match image for multiple screens my suggestion is to use
Nine patch image rather than .png and .bmp
for creating nine patch image
http://developer.android.com/tools/help/draw9patch.html
Related
The previous dev on this project made all of the drawable folders based on large or xlarge. We've refactored layouts and values to utilize the 'sw' folders. how would the drawable folders for large and xlarge map out?
here's the folders in question:
drawable
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
drawable-large
drawable-large-hdpi
drawable-large-xhdpi
drawable-large-xxhdpi
drawable-large-xxxhdpi
drawable-xlarge
I'd like to keep the handset folders as-is (the ones NOT tagged with large or xlarge) but convert the others to sw folders. Anybody know the correct sw equivalents for those folders?
From this link, we see that:
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra-high-density screens; approximately 320dpi. Added in API Level 8
large: Screens that are of similar size to a medium-density VGA
screen. The minimum layout size for a large screen is approximately
480x640 dp units. Examples are VGA and WVGA medium-density screens.
As far as smallestWidth or sw, it says the following:
Some values you might use here for common screen sizes:
320, for devices with screen configurations such as:
240x320 ldpi
(QVGA handset)
320x480 mdpi (handset)
480x800 hdpi (high-density
handset)
480, for screens such as 480x800 mdpi (tablet/handset).
600,
for screens such as 600x1024 mdpi (7" tablet).
720, for screens such
as 720x1280 mdpi (10" tablet).
Edit:
The order in which a drawable is labeled with suffixes is important. For example:
In this case, drawable-large-hdpi will pick the
large attribute first, meaning that its pixel density approximately 480*640 dp units. Then,
hdpi is approximately 240dpi. Android will use hdpi based on the device dots per inches of the device running.
I believe that 480*640 will translate to layout-sw600dp, screen with smallest width of 600dp. Usually for tablets with screen of 7 inches in diagonal measurement.
For safety measures, you can create a folder under layout-sw600dp-hdpi and layout-sw600dp-xhdpi and test it and see how it runs on hdpi and xhdpi tablets.
Note:
Keep in mind that developers who created the previous folders e.g: drawable-large-hdpi may have put whatever they wanted in wherever. So it does not mean that an image within drawable-large-hdpi is surely of 480*640 dimensions and is only for hdpi devices.
In my android app I am using mdpi, hdpi and xdpi resource folder and I have placed different sets of images on the basis of resolution in these folders for example:
mdpi contain images of 320x 480 resolution
hdpi contain images of 480 x 800 resolution
xhdpi contain images of 720 x 1280 resolution
When I load the application in Samsung S3, for tabs in tabwidget, it takes images from xhdpi folder and for the buttons it take images from hdpi folder.
Just try this once..
place 320 X 480 images in drawable-mdpi,
place 480 X 800 images in drawable-hdpi,
place 720 X 1280 images in drawable-xlarge-v11.
Once check with name conflict of images also. Use same image names in all folders.
Put the images for buttons in x-hdpi folder. When android don't images in x-hdpi folder, it goes to find it in next lower resolution folder.
But the either case of this is not true. When android requires any image from hdpi folder, it doesn't take images from x-hdpi folder. Infact it will crash if the images are not present in lower resolution other than hdpi.
i am working on an android app. as this should be all screen size supportive .but it is not working properly.
I can I set that for 480*800 size it will take images from drawable-hdpi folder?
Screen size and dpi aren't the same thing. DPI is the number of pixels per inch. a 480x800 screen can still be any dpi level- it would just be a smaller screen with higher dpi.
You can try doing a size override with drawable-swNdp where N is a pixel value. That works for layouts, I believe it also works for drawables.
To support on all resolution devices put different resolutions images in different folders in drawable as,
drawable-ldpi - 240 * 380
drawable-mdpi - 320 * 480
drawable-hdpi - 480 * 800
drawable-xhdpi - 720 * 960
For more info about resolution refer this link :
http://developer.android.com/guide/practices/screens_support.html
I have published an app which have an mdpi, hdpi, xhdpi and xxhdpi image for the app icon.
I have received some feedback that on ldpi devices my icon wasn't used and the default one from android is used.
Why is that ? My app has a drawable-ldpi folder but it is empty. Should I delete it ? Is this specific to the launcher icon ?
EDIT : I don't have any image in the drawable folder, only xml shape or selector. I have see this issue with a ldpi screen of 240 x 320 pixels (Samsung Galaxy Y running Android 2.3.6).
I'm talking about this application : http://code.google.com/p/morpion-1vs1/ (the code is public because otherwise I should pay for the repository, I know the activities are a bit messy)
Here is the icon used :
Put a 36x36 pixel size version of your application launcher icon "j5oDi.png" into "drawable-ldpi".
The Launcher icon sizes are described here: Launcher Icons -> Size and Format
You should have icon files in each of those resource folders at various sizes:
res/drawable-ldpi (120 dpi - Low density screen): 36x36 px
res/drawable-mdpi (160 dpi - Medium density screen): 48x48 px
res/drawable-hdpi (240 dpi - High density screen): 72x72 px
res/drawable-xhdpi (320 dpi - Extra-high density screen): 96x96 px.
I am having this issue where I have HDPI and XHDPI folders in my eclipse project both have different images resolutions, both Images in the different folders are exactly the same but they differ in size.
So I lunched my app on Samsung Galaxy Note 1 which have 800 x 1280 pixels, 5.3 inches (~285 ppi pixel density) display, but it's loading drawables from the XHDPI folder.
I have tested that by modifying one image in HDPI folder and keep it as it is in the XHDPI folder, the result was note 1 is loading from the XHDPI folder, am I missing something here, it suppose to load images from the HDPI folder because it's screen density is smaller than 320 DPI.
You can check what density your device is set to with
Log.v(TAG, "density=" + getResources().getDisplayMetrics().densityDpi);
am I missing something here, it suppose to load images from the HDPI folder because it's screen density is smaller than 320 DPI
The maker of the device chooses which density bucket to use. Since ~285 is closer to 320 than 240, it is not surprising to me that Samsung chose -xhdpi. Others have reported that it indeed is an -xhdpi device.
If you are finding that -xhdpi resources result in slightly too large of images in certain places, you may need to control that in those places (e.g., set the ImageView size to the size that you want and set android:scaleType to be how you want the image to be adjusted).
it suppose to load images from the HDPI folder because it's screen density is smaller than 320 DPI.
why that?
HDPI is 240 ppi
XHDPI is 320 ppi
Note 1 has a 285 which is closer to XHDPI (|285-320|=35) than to HDPI (|285-240|=45)
On Android developer website, it says,
"hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi)."
Any device which has a density higher than 240dpi should load layouts and images from xhdpi folder.
Thus, your app on galaxy note which has 285dpi loads images from xhdpi folder.