I have a problem in mapping between old and new Android drawable resolutions. I have an app with drawable files named:
drawable
drawable-hdpi
drawable-large-hdpi
drawable-large-mdpi
drawable-ldpi
drawable-sw800dp
drawable-xhdpi
What are their corresponding in
ldpi
mdpi
hdpi
xhdpi
xxhdpi
xxxhdpi
Some of them are the same as below, e.g. hdpi = hdpi
Large and sw800dp belong to the screen size and not to the resolution.
AFAIK, none of the resolution modifiers you stated are "new". They have all been around for a while. The other modifiers you currently use are for other properties, not resolution.
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.
So i have a very stupid question. I am new to Android and trying to understand how the resources folder work.
I see that I need subfolders with ldpi, mdpi, hdpi, xhdpi, xxhdpi naming but does the naming of the actual image need to be different?
For example, If I have an image names icon.png.
In iOS: mdpi would be icon.png, xhdpi would be icon#2x.png and xxhdpi would be icon#3x.png.
Do I need to give different naming in Android?
If I put icon.png in 5 different folders with 5 different sizes, would there be a name conflict?
It would be very good if someone can explain it.
I read all standard android explanations but I want to make sure with someone who has actually done it.
Thanks for your time.
Directory Naming:
You do not need to provide a different suffix to your image file name for different screen sizes in Android like you do in iOS. The file name should be exactly the same for all the images of different sizes.
However, you need to follow Google's guidelines/conventions for directory naming. Images are called 'drawables' in Android.
Under the 'res' directory, place each image under a directory called drawable-<suffix>. Replace the <suffix> with the screen density qualifier (i.e., mdpi, hdpi, xhdpi, xxhdpi etc.)
Google recommends that you also create a directory called drawable (with no suffix) for default images. These default images will be used as fallback when Android does not find a specific image size for the user's device.
Example directory structure:
res/
drawable/
icon.png
background.png
drawable-mdpi/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
drawable-xhdpi/
icon.png
background.png
drawable-xxhdpi/
icon.png
background.png
Image Size Ratios:
The correct way to create images for different screen densities is by starting at a base image size for mdpi.
Say for example your base icon size is 48px x 48px. Then:
mdpi: 48px x 48px (1x)
hdpi: 72px x 72px (1.5x)
xhdpi: 96px x 96px (2x)
xxhdpi: 144px x 144px (3x)
xxxhdpi: 192px x 192px (4x)
References:
Directory structure:
http://developer.android.com/guide/topics/resources/providing-resources.html
For size ratio comparison (mdpi vs hdpi vs xhdpi vs xxhdpi) go to:
http://developer.android.com/design/style/iconography.html
If I define drawables for a density qualified folder (eg drawable-hdpi), and also drawables to fall back on in drawable-nodpi, will a high density device use the -hdpi over the -nodpi?
What about if I take it a step further and also have the same setup for -land folders.
I'm not sure what the precedence is for nodpi, but that should never be a problem. It sounds like you are misunderstanding the nodpi qualifier. You should not use nodpi as a fallback for assets that you don't provide at the device's density bucket. The correct fallback is a folder with no density qualifier (e.g. drawable/).
If the system cannot find an asset at the device's density (e.g. it is an ldpi device and you don't have a drawable-ldpi folder), it will fall back to a folder without a density qualifier, *not the nodpi qualifier`.
The nodpi qualifier is used when you want to specify a resource that will be used for all densities and that you do not want Android to scale. Assets in the other density folders (e.g. drawable-xhdpi) will be scaled to the actual screen size. If you use the nodpi qualifier, you should not provide that asset in any other resource folders.
It is also important to note that with screen density qualifiers, Android will also prefer to use a lower density asset over an unqualified resource. If you have an xhdpi device, but you only have a drawable and a drawable-mdpi folder, Android will check for the asset in the mdpi folder before the unqualified folder.
drawable-nodpi will bypass scaling and drawable will use the default scaling:
mdpi = 1x
hdpi = 1.5x
xhdpi = 2x
xxhdpi = 3x
xxxhdpi = 4x
drawable-nodpi is efficient if your code will be doing its own scaling
(or no scaling) and you don't want the image pre-scaled by Android.
There is also drawable-anydpi, just to make things more confusing.
drawable with no specifications will be used if an exact match on density and screen specifications does not exist. drawable-nodpi will be used after drawable.
UPDATE If you have both drawable and drawble-nodpi, the select order is either a more complex rule not documented or Android is broken. Through experimentation I confirmed that devices with screen density < xhdpi will correctly select the drawable image. Devices with screen density >= xhdpi will select the drawable-nodpi.
Selection rule:
1. Pick match to screen density, one of these:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
If no match on density, then select one of these
drawable (automatic scaling mdpi=none... xxxhdpi=4x)
drawable-nodpi (no scaling)
drawable-tvdpi
drawable-anydpi (no scaling)
It depends.
First of all nodpi is not a fallback folder. If you have a hdpi device, the system will look for hdpi folder first. nodpi folder contains resources that are not meant to be scaled.
drawable/ can be used as a fallback folder in case device density specific resources are not present.
Then, if we look at the possible Qualifier Values for the Screen Pixel Density(dpi), these are listed as:
ldpi
mdpi
hdpi
xhdpi
xxhdpi
xxxhdpi
nodpi (Non-scaling resources go here)
tvdpi
anydpi (Resources in this folder take highest precedence)
nnndpi
Note: You should put all those resources in the drawable-nodpi folder that you do not wish to be scaled. To support multiple screens, Android prefers to scale down a larger original image instead of scaling up a smaller original image. These resources should not be present in any other drawable-qualifier folder else these might be scaled which kind of defeats the whole purpose.
It must also be noted that:
Using a density qualifier does not imply that the resources are only for screens of that density. If you do not provide alternative resources with qualifiers that better match the current device configuration, the system may use whichever resources are the best match.
Here is the Resource Selection Flowchart that the system uses to find the best match:
The drawable-nodpi qualifier is used when image/asset is not need to be scaled.
Drawable in the other density folders (e.g. drawable-xhdpi) will be scaled to the actual screen size.
drawable-nodpi for constant size in all density devices.
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
I have a high quality icon. I copied that to drawable-xdpi folder. Can I use icon in drawable-xdpi for low density screens without creating drawable-ldpi folder?
Think it's drawable-xhdpi folder. Yes, Android will look for drawable in the folder that best fits the display type. If it is not found, it will try to determine the next best to use.
yes. Do not put that icon in drawable-ldpi folder.
If your app runs on ldpi device and OS does not found the resources in drawable-ldpi. Then it will use resources from drawable-xhdpi after scaling.
UPDATE
Quality will not be the same..as it is ldpi device.
It will calculate the resolution of new Image like this
resolution of xhdpi icon = x * y
resolution for ldpi will = x/2 * y*2
Why dont u put the image in MDPI or just drawable Folder ?