single image for all ldpi, mdpi, hdpi, xhdpi in android - android

Perhaps we use one image for all ldpi, hdpi, mdpi and xdpi where we need to keep the image(in which folder). This is a bit confusion to me. Can anybody clarify my confusion?

Just keep it in res/drawable.

This is not recommended as the images you use will then not scale well for different device screen sizes. But if you place an image in res/drawable this will work.

Instead of creating all of the different folder buckets, drawable-ldpi, drawable-hdpi, etc. Just create one folder, drawable, and then put your images in there and when Android searchs for the image and doesn't find the other folders it will default to the drawable folder as the only resource. This folder is understood by Android to be equal to the drawable-mdpi and will scale the images accordingly.
EDIT: Also available is the res/drawable-nodpi, This will not scale your image at all and it will retain the same size on all screens.

Take a look at How to Support Multiple Screens
The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate.
So yes, drawable folder is what you are looking for.

Related

Will a density qualified drawable folder or drawable-nodpi take precedence?

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.

Which image size should be placed in the neutral drawable folder?

Which size of an image should be placed in the neutral drawable folder?
I have an icon file in 5 different versions:
24x24 = ldpi
32x32 = mdpi
48x48 = hdpi
64x64 = xhdpi
96x96 = xxhdpi
On the other hand I have 6 different folders:
/drawable
/drawable-ldpi
/drawable-mdpi
/drawable-hdpi
/drawable-xhdpi
/drawable-xxhdpi
5 Files and 6 folders means that either one folder has to stay empty (which one?) or one file has to be used twice?
This is what the docs say:
If no matching resource is available, the system uses the default
resource and scales it up or down as needed to match the current
screen size and density
The "default" resources are those that are not tagged with a
configuration qualifier. For example, the resources in drawable/ are
the default drawable resources. The system assumes that default
resources are designed for the baseline screen size and density, which
is a normal screen size and a medium density. As such, the system
scales default density resources up for high-density screens and down
for low-density screens, as appropriate.
However, when the system is looking for a density-specific resource
and does not find it in the density-specific directory, it won't
always use the default resources. The system may instead use one of
the other density-specific resources in order to provide better
results when scaling. For example, when looking for a low-density
resource and it is not available, the system prefers to scale-down the
high-density version of the resource, because the system can easily
scale a high-density resource down to low-density by a factor of 0.5,
with fewer artifacts, compared to scaling a medium-density resource by
a factor of 0.75.
OK, that the mdpi version should be placed in drawable-mdpi, ldpi in drawable-ldpi, etc. is out of question. But which version goes to the neutral folder?
Should I place the xxhdpi files there (scale down if no match is found)? What about the -xxhdpi folder than? Keep it empty or place the files there as well?
The default /drawable folder expects mdpi images. And mostly used in 2 cases:
To have non-density dependent images. eg: selectors, which indirectly link to images from density named folders again.
To have all the images in only this folder and ignore all the other drawable folders. In which case the images will be scaled depending on
the screen density.
For your case:
You can keep only xml files like selectors in the default /drawable
folder and other images in their respective folders

Android Application Background Resolution

I want to design a background for android application using Photoshop , let's say I have Samsung S4,So I set the resolution to the maximum of that device which is 1080x1920 and 441dpi
Now,my question is where should i insert it in what subfolder of Resources and depending on what we choose that folder
-drawable-hdpi
-drawable-ldpi
-drawable-mdpi
-drawable-xhdpi
-drawable-xxhdpi
What image feature decides on which folder image should be in?
Hopefully, this image will show you which category it falls into:
As you can see everything larger than 400dpi is xxhdpi, so you should place it there.
Also check out the DisplayMetrics page.
EDIT: To answer your last question. There isn't any image feature that determines where it belongs, the folders are simply used to load images with different resolutions onto different screens. For example if the picture containing text has high resolution and you place it on a low density screen, the text would be (physically) too small to read. So you place a higher resolution image in hdpi or xhdpi folder and resize it so it has smaller resolution and place it in ldpi and mdpi folders.
Please refer to this, it is from google!
http://developer.android.com/training/multiscreen/screendensities.html
You should put on drawable-xxhdpi folder.
A brief explanation about the drawable resources:
The drawable resources are, by default, divided in 6 generalized groups based on its pixel density:
ldpi: Low density drawables (~120 dpi)
mdpi: Medium density drawables (~160 dpi)
hdpi: High density drawables (~240 dpi)
xhdpi: XHigh density drawables (~320 dpi)
xxhdpi: XXHigh density drawables (~480 dpi)
xxxhdpi: XXXHigh density drawables (~640 dpi)
The scaling ration between these drawables should be 3:4:6:8:12:16
You only need to provide density-specific drawables for bitmap files (.png, .jpg, or .gif) and Nine-Path files (.9.png). If you use XML files to define shapes, colors, or other drawable resources, you should put one copy in the default drawable directory (drawable/).
Even if you don't provide alternative drawable resources for the different groups of density, the Android system will find the best matching drawable and scale it for you. But is recommended to provide alternative drawable resources in order to ensure to always have smooth drawables in all devices.
You might want to take a look here.

How sort images by resolution and density?

On this page in table 3 at the bottom it says there are small, normal, large and extra large screen for each density (ldpi, mdpi, hdpi, xhdpi): http://developer.android.com/guide/practices/screens_support.html#support
For example, if I create mdpi normal screen (320x480) and mdpi large screen (600x1024) should I put all images for both resolutions in mdpi folder? If yes, how should I name those images because those are the same images with different sizes?
should I put all images for both resolutions in mdpi folder?
Yes. The size of the images should be the same among all screen sizes, they should vary only by density.
In this case you should use drawable-mdpi and treat your layout to better use the extra space you may have in larger screens.
If you want to give images specifically for large screen mdpi then you can create a new folder drawable-large-mdpi.
Check out : http://developer.android.com/guide/practices/screens_support.html#qualifiers
What ever the screen size and resolution, same images apply for similar dpi screens. Android will automatically resize your images to fit in the screen as you defined regardless of the size and resolution but on basis of dpi.
That means you have to put same images for all same dpi layouts.
From the same link:
To use a configuration qualifier:
Create a new directory in your project's res/ directory and name it using the format: -
is the standard resource name (such as drawable or layout).
is a configuration qualifier from table 1, below, specifying the screen configuration for which these resources are to be used (such as hdpi or xlarge).
You can use more than one at a time—simply separate each qualifier with a dash.
Save the appropriate configuration-specific resources in this new directory. The resource files must be named exactly the same as the default resource files.
Search for "Using configuration qualifiers"

Using Android drawable resources conditionally on density and screen size

I want to create an Android app with ImageButtons that look good, and appropriately-sized, on a wide variety of devices. I'm aware that multiple levels of conditionality can be built into Android drawables, the simplest being to create folders like
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
for different densities of bitmap. However, buttons that look good on an mdpi phone look poky on an mdpi tablet, and I'd rather use the hdpi bitmaps for that application. There is a way to do this using folders named like
drawable-small-ldpi
drawable-normal-ldpi
drawable-large-ldpi
drawable-xlarge-ldpi
drawable-small-mdpi
drawable-normal-mdpi ...
etc. As you can see there are sixteen different folders to cover conditional screen sizes for each density. I can probably reduce this somewhat by using defaults like
drawable-ldpi
drawable-large-ldpi
drawable-xlarge-ldpi ...
but my intention is to use the SAME drawables for large and x-large screens on one density as for the small and normal screens on the density above. I feel that this method is a waste of resource space in the APK. Is there a way to create SINGLE drawable folders that contain images targeted for:
Small low-density devices
Large low-density AND small medium-density devices
Large medium-density AND small high-density devices
Large high-density AND small extra-high-density devices
Large extra-high-density devices?
Alternatively, is there another way to assert conditionality based on device size AND device density?
Taken from http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources:
"When you have a resource that you'd like to use for more than one device configuration (but do not want to provide as a default resource), you do not need to put the same resource in more than one alternative resource directory. Instead, you can (in some cases) create an alternative resource that acts as an alias for a resource saved in your default resource directory."

Categories

Resources