Android Launcher Icon - are my default / mdpi resources redudant? - android

I'm new to Android development (using Mono for Android), I've read this, this this and a some other questions here on SO but I'm not sure on how to provide all necessary Icon files for my application.
From the template project, the IDE created for me a drawable/ folder with an 48x48 px Icon.png file.
Since I need to provide alternative resources, I grabbed a PNG file which serves as my application icon and used the Android Asset Studio (mentioned in the docs) and it generated the following files for me:
drawable-hdpi/ic_launcher.png (72x72 px)
drawable-mdpi/ic_launcher.png (48x48 px)
drawable-xhdpi/ic_launcher.png (96x96 px)
drawable-xxhdpi/ic_launcher.png (144x144 px)
(I don't know why, but the Android Asset Studio did not generate the ldpi version, so I resized myself a 36x36 icon.)
Now I'm lost
1. Should I maintain a 48x48 px copy in both drawable-mdpi/ and drawable/ ?
If I keep the icon only in the drawable-mdpi/, may the application crash on older devices / versions of the Android (because the default resource is missing)?
1. If I keep the icon only in the drawable/ (the fallback), what is the point in using drawable-mdpi/ at all?
Since I don't know exactly what to do, I'm left my project drawable folders as follows:
drawable/ic_launcher.png (48x48 px)
drawable-hdpi/ic_launcher.png (72x72 px)
drawable-ldpi/ic_launcher.png (36x36 px)
drawable-mdpi/ic_launcher.png (48x48 px)
drawable-xhdpi/ic_launcher.png (96x96 px)
drawable-xxhdpi/ic_launcher.png (144x144 px)
But it is still not clear for me.
EDIT:
If I provide all possible "alternative" resources, then the default (drawable/) resource folder will become redundant, thus I could delete it. However I'm reluctant of not providing the default resources because it seems more reasonable to do the opposite: first provide the "default" resources and then provide "alternative" resources as needed.

This quote is a little long, but you should read though what the documentation has to say about this:
At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:
1.The system uses the appropriate alternative resource
Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.
2.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.
So, the system will look for the best sized drawable for whatever device the application is running on. If the system is looking for a launcher icon of 48x48, it will look in drawable-mdpi/ first because the docs suggest you put a 48x48 icon in that folder. Since you've provided that already, there's no reason why the application would ever have to look in the drawable/ folder for a default image. Even if it did, it would not be beneficial since you've already provided an icon of the same size.
If you've provided even just one size of a particular drawable, your app shouldn't crash on any devices, even if the size you provided is very wrong. The image will just look bad in that case, because the system will load the single image you have provided. So, if you've got the image in the drawable-*dpi folders, you won't need a copy in drawable/.
TL;DR
No, you won't need to put a 48x48 copy of ic_launcher.png in the drawable folder if you've already got one in drawable-mdpi/, because the system will choose that one first.

Related

android - drawable disappears when not in correct resolution

I have the fallowing drawable called background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#color/gradient_bottom"
android:endColor="#color/gradient_top"
android:type="linear" />
</shape>
</item>
</selector>
when the xml is under the drawable folder, in some reproducible cases (not sure why, probably has something to do with high memory consumption) the background disappears.
However, when I recreate the scenario and I put the same xml in all the drawable resolution folders, the background doesn't disappear (i.e drawable-hdpi, drawable-xhdpi etc.)
This kind of thing isn't supposed to happen,
can someone explain why does it happen and how to fix it more elegantly ?
P.S -
when i put a solid color as a background this issue doesn't happen
the issue is also occurs for a custom button background, and fixed when i put the custom background in the drawable resolution folders
I recommend to use resource directories with the dpi qualifiers as possible. Otherwise you can get OutOfMemory errors with some devices. Explanation here:
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:
The system uses the appropriate alternative resource
Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.
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.
Source

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

different resources for different screen size android app

I am developing an andriod app using eclipse. I have the following folder structure.
Xml file folder:
/res/layout
/res/layout-large
/res/layout-large-mdpi
/res/layout-mdpi
/res/layout
/res/layout-xlarge
Image folder:
/res/drawable
/res/drawable-hdpi
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-xhdpi
/res/drawable-xxhdpi
I have used this code in my manifest.xml
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
I have a logo image of different sizes in the drawable folders. But now all my layout.xml using the image from /res/drawable-mdpi only. How to fix this?
Check(TEST) this before you try!!!
This is not perfect answer for your Question, But this is a chance if you have minimum number of Images in your app:
Go through the developer site here :
and read complete details,
For better results on your app consider 1,2 points before "Using configuration qualifiers" paragraph in the above link.
At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:
The system uses the appropriate alternative resource
Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.
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.

Screen density qualifiers

There is hdpi and nodpi qualifier folders in my project. Suppose I have installed the app in a hdpi density device. From which qualifier folder will it pick the resources ?
the hdpi resources will be used. Device will first check the corresponding dpi resource folder.
according to doc
The system uses the appropriate alternative resource Based on the size and density of the current screen, the system uses any size- and
density-specific resource provided in your application. For example,
if the device has a high-density screen and the application requests a
drawable resource, the system looks for a drawable resource directory
that best matches the device configuration. Depending on the other
alternative resources available, a resource directory with the hdpi
qualifier (such as drawable-hdpi/) might be the best match, so the
system uses the drawable resource from this directory.
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 nodpi resources are also default resources type. The only difference is it doesn't scall the images but drawable does.
drawable-nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
if you have an images with same name in hdpi and nodpi drawable folder when you are running in hdpi it will pick from HDPI darwable only.
There is an image with 100 x 100 px that I want to show in any resolution/density as same size then we need the drawable-nodpi folder.

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