Android. ldpi device won't choose images from mdpi folder - android

I've only placed mdpi and hdpi images inside each folder, but when I run my app on an ldpi device, it won't pick the images from the mdpi folder, but from the hdpi folder. Why is that? Any ideas on what i'm doing wrong?
P.S. If I place images specifically for the ldpi device inside the ldpi folder, it uses those, but if i delete them, it uses the hdpi ones.
Help.

That is the default behavior of Android. LDPI is basically half of HDPI and ANdroid basically picks images from HDPI, scales it to half the size and uses it.
Read the last note on this link
http://developer.android.com/training/basics/supporting-devices/screens.html

Android checks for the particular density.If the reference of the image is given than it checks for the availability of it and sets the image according to the density but if its not available than it will take the default image which resides in Hdpi folder which is the default behavior of Android.
Take an example of the default image of Android that is ic_launcher,if its present in a single folder,android is going to set it because it first find its availability than density.

Related

Folders for different screen densities for Android

There are multiple groups of screen densities of Android phones (ldpi, mdpi, hdpi and so on).
I had a folder "drawable" with picture size 1920 x 930 pixels which is for xxxhdpi, I guess.
I want to arrange pictures for all screen densities from xxxhdpi to hdpi. So, I should rename my existing folder: "drawable" -> "drawable-xxxhdpi". Then, I should create 3 additional folders for others. Do I understand it right?
How would actually the program choose proper folder?
For example, I also have smaller pictures now. Should I also resize them? If I don't duplicate them in new folder, will the program crash?
Will the program crash on phones with, for example, hdpi if I don't create a folder for hdpi?
Couldn't get how it works, would be grateful for an explanation.
First of all be sure that you are in the "Project" view because you will not see all the folders if you are in "Android" view. Then instead of renaming drawable folder create the others and keep drawable for some files that doesn't need to resize (for example defining a background). Folders should be:
drawable-hdpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
Selection between them will be done automatically according to the screen of the device you are installing the app. If screen is xxxhdpi and you don't have a file for that resolution the app will take the smaller and so on. Obviously this will not be a great UI performance but you should not have problems with crashes.
There are many online App icons generators in the web so you can take a big icon and put it there so you get the icons for all sizes

Using hdpi drawables in mdpi tablets without creating image copies

I want my app to be as lightweight as possible. So i put all my images inside drawable-xxhdpi and let the Android OS to resize them.
However for the 10 inch mdpi tablets i want to use hdpi images. I know, that it is possible to create drawable-sw720dp-mdpi and put there hdpi images. But this will increase apk size, which is not the option. So, is it possible to make such a change without making drawable copies?
create a drawable folder in res folder of project and paste all images there...it will resize all images according to device size
Let's say you have a set of resources called icon_text.png; and you place one in the drawable-xxhdpi folder and another one in drawable-hdpi folder. That is your scenario, right? Any device that is mdpi (it doesn't matter its size) will pull resources (if available) from the hdpi folder. The system will pick the closest match, and mdpi is closer to hdpi than to xxhdpi.

What if image is not found in drawable-ldpi?

I have one image that is in all folder except drawable-ldpi folder. Then if i will run my project in ldpi devices then from which folder it will try to find that image? or my app will simply get crash? I am not having this image in my drawable folder,too.
Test case i performed using mdpi device --
Placed image in drawable-xxxhdpi folder only, worked fine.
Placed image in drawable-ldpi folder only, worked fine.
Came to conclusion it perform both scale up and scale down
Regards
It is not required to have images for all the densities, only one is enough. The system will scale it up/down when needed. So the best approach is to have images for the highest density supported (xhdpi or xxhdpi).
It will scale but you might run into problems when a phone with a ldpi tries to load xhdpi or xxhdpi images.
Google's recommended that it is useful when you are creating different images for each resolution and not just resizing it.
And also in present when Eclipse creates launcher icons, it only creates them for mdpi, hdpi, xhdpi, and xxhdpi. Based on that creating ldpi icon is not necessary and that mdpi will be scaled down automatically.
In your case it will try to find image in mdpi folder.
Dont worry, FYI ldpi device is closed before some months and now no any new ldpi device will come in market. But if any user will install your app in ldpi device then it will find closest image as compare to ldpi and will show it.
But that image must be in any of the folder.
If the user is using a device with a low density screen, and a ldpi resource is not found, the resource with the closest density is used and scaled down.
By the way, I wouldn't even bother with mdpi, let alone ldpi.
Your app will not crash until you have the named image in at least one of drawable folders. System will show the closest density image.

Android xxx-hdpi real devices

I'm gonna release my app, it's a 1.2Mb apk that includes about 120 icons in 4 different formats (ldpi, mdpi, hdpi, x-hdpi).
If I add xx-dpi and xxx-hdpi icons the apk grows bigger and loading time increases.
There are many entry-level devices out there with really loooow memory and I'd like my app to run everywhere.
Do I really need to add xx-hdpi?
And is there a real device that requires xxx-hdpi?
You shouldn't really need xxxhdpi. It was only introduced because of the way that launcher icons are scaled on the nexus 5's launcher
Edit
Back when I answered in Jan 2014, the Nexus 5 was the only device using xxxhdpi. Now many devices including the Nexus 6 and LG G3 use it. So it would be a good idea to include it in your app.
We had to add xxxhdpi to our app for the Nexus 6, LG G3, and Samsung Galaxy Note 4. There will be more xxxdhpi devices in the future.
You do not need xxxhpdi for most of your images. You only need xxxhdpi for your launcher icon. Please see http://developer.android.com/guide/practices/screens_support.html
You should not use the xxxhdpi qualifier for UI elements other than the launcher icon.
It's pretty clear in the above quote. In the example folder layout they give, they show all the densities for the res/drawable folders up to -xxhdpi, but then they show the res/mipmap folders up to -xxxhdpi. Here are more quotes:
xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above.
The mipmap-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
You don't need ldpi, because Android downsizes hdpi to ldpi.
From https://developer.android.com/design/style/iconography.html
Note: Android also supports low-density (LDPI) screens, but you normally don't need to create custom assets at this size because Android effectively down-scales your HDPI assets by 1/2 to match the expected size.
From Android iconography documentation itself:
Some devices scale-up the launcher icon by as much as 25%. For example, if your highest density launcher icon image is already extra-extra-high density, the scaling process will make it appear less crisp. So you should provide a higher density launcher icon in the drawable-xxxhdpi directory, which the system uses instead of scaling up a smaller version of the icon.
Note: the drawable-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
more on: http://developer.android.com/design/style/iconography.html
I don't know if there is a device that requires xxx-hdpi, but xx-hdpi is not yet used very often. But the same goes for ldpi, almost no device still requires ldpi. If you just do mdpi, hdpi and xhdpi, it will be just fine. If a device requires something bigger or smaller android just scales it to the right size.
Heres what Android says about this:
Provide different bitmap drawables for different screen densities
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. The
configuration qualifiers you can use for density-specific resources
are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high).
For example, bitmaps for high-density screens should go in
drawable-hdpi/.
You can find the documentation here:
https://developer.android.com/guide/practices/screens_support.html
Hope this helps
I think you should focus on the most popular screen densities, which are hdpi, xhdpi, and xxhdpi. See this link for the current worldwide average distribution of each density.
Forget Everything & make it Simple !
Just store highest resolution images in only one folder. Either in drawable-hdpi, & delete other images from the rest drawable folders.
I have tested it in various devices & it works like a charm...

Android using drawable folders

Simple question. How does android work with drawable folders if any folders are empty ? Lets say I have images only in folder "drawable-hdpi". When I start application on emulator with higher dpi "drawable-xhdpi" it load images from "drawable-hdpi" (of course in bad size). Also when I start application on device with lower dpi "drawable-mdpi" it load images from "drawable-hdpi".
My question is - does it mean if doesn't exist images for current device dpi, android system takes images from other folder it is not empty ? Till today I thought, when images in current dpi are not present, application doesnt work.
It takes the near dpi, and scales the image up or down by the dpi difference between the target dpi and the folder dpi. If in the "drawale" folder (no dpi), no scaling takes place.
http://developer.android.com/training/basics/supporting-devices/screens.html
Note: Low-density (ldpi) resources aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.
It works. It first check in the current dpi folder for the resources. If not found then it use other available resources

Categories

Resources