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
Related
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.
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.
I have the following drawable folders
/drawable/
/drawable-hdpi/
/drawable-ldpi/
/drawable-mdpi/
/drawable-xhdpi/
If I have an image resource, do I need to create 5 (or 4?) different resolution versions of the file? Let's say I make just two versions and put them in their respective folders:
/drawable/
/drawable-hdpi/image.png
/drawable-ldpi/
/drawable-mdpi/image.png
/drawable-xhdpi/
What happens when someone on a LDPI or XHDPI device visits an Activity that needs to display image.png? Does it just not show it? Does the app crash? Or does Android follow a resource cascading system, show the version that is nearest to the current screen density?
Also, in this case I don't have an image.png in the /drawable/ folder. Is this bad? Should every single resource have (at minimum) a version in the /drawable/ folder?
Also, if you have specified all 4 screen density drawable folders (xhdpi, hdpi, mdpi, ldpi), then what is the point of the normal /drawable/ folder? When will it ever get used?
If I have an image resource, do I need to create 5 (or 4?) different
resolution versions of the file?
No, you don't have to
What happens when someone on a LDPI or XHDPI device visits an Activity
that needs to display image.png? Does it just not show it? Does the
app crash? Or does Android follow a resource cascading system, show
the version that is nearest to the current screen density?
Android uses a nice cascading system for its resources. This page explains it a bit. Afaik LDPI devices use the MDPI resource if a LDPI resource isn't available, XHDPI uses HDPI resources. (I could be a bit off, I can't recall the exact rules) Your app doesn't crash.
Your app crashes if you only have higher resolution resources than the screen can take.
Also, in this case I don't have an image.png in the /drawable/ folder.
Is this bad? Should every single resource have (at minimum) a version
in the /drawable/ folder?
No, not necessary.
Also, if you have specified all 4 screen density drawable folders
(xhdpi, hdpi, mdpi, ldpi), then what is the point of the normal
/drawable/ folder? When will it ever get used?
The drawable folder is for images that don't need scaling, and things like shape drawable resource XML files etc.
I am new to android and this concept of multiple resources is killing me and its Halloween =)
Ok so for Normal screen we have following HDPI per http://developer.android.com/guide/practices/screens_support.html#range
WVGA800 (480x800)
WVGA854 (480x854)
600x1024
so my image will go in drawable-hdpi. should image be 480x800, 480x854, 600x1024, or all 3 in the drawable-hdpi?
If all 3 are doing to be in drawable-hdpi, how I will name them? They can't have same names.
Thank you in advance
The common drawable folders are drawable-hdpi,drawable-mdpi,drawable-ldpi.
These folders are used to tell android which set of image to use on different situations.
The different names that can be used are given here.
When a small ldpi phone is being used and it tries to refer an image named icon.png. It first refers the drawable-ldpi folder. If it doesn't find it there, it moves to the other folders till it finds the image. But if the phone was an hdpi device, android would first look into the drawable-hdpi folder. So if icon should be of different sizes, you put the different sized image in each folder with the same name. And android will decide which folder to access the image in run time.
This might be a bit confusing in the beginning but you will get used to it after a while.
Hey all, right now I have a drawable-hdpi, drawable-mdpi, drawable-ldpi folder inside my res directory... I hear that android now filters out applications based on screen size and density. All of my images are inside the drawable-hdpi folder. Should I make just 1 folder called "drawable" and delete the other 3? Or should I convert all the images to the proper size and place them inside all three folders?
Leave the folders as they are and put your medium density images in drawable-mdpi and hign density images in drawable-hdpi folder. I would leave the small density screens and let android scale them. But if you are worried about small density then put those in the drawable-ldpi directory too.
There are only a very few devices that support small screens.
Now for supporting multiple screens you need to make some changes in your manifest. Here is the explanation of what developers need to do to support multiple screens.
A note of caution if you are supporting 1.5 devices. In this case put all the images in your drawable-mdpi into drawable folder. That is because 1.5 devices do not support multiple screens and they recognize images in drawable folder.