I am on one really big project that was started sins the time of android 1.5.
This project evolved as android was evolving and at this point supports 2.3 and above.
Now I got this problem I have a lot of drawables in drawable-hdpi,drawable-mdpi,drawable-ldpi but also in drawable folder.
Generally the concept of this 3 folders(drawable-hdpi,drawable-mdpi,drawable-ldpi) it is clear to me but my confusion comes with the images in drawable folder.
for example I have an image named myimage.png and this image is present in drawable-hdpi,drawable-mdpi,drawable-ldpi folders with resolution 72x72,48x48,36x36 respectively but this image is also present in drawable folder.
My question is why ? when does the image from drawable folder is used ? is this image forgotten to be removed ? of it is used in some cases ? I have tried to remove this image and the application works just fine. I also have put just a green color with resolution 72x72 and this image is never drawn
so can someone clarify me the existence of the drawable folder ?
I know that if I do not have the dhpi,mdpi and ldpi folders then I need to put the images in drawable but what is the point of images in drawable when this 3 folders are present ?
Thanks
EDIT
one more question, what if I have image in drawable-hdpi but not in ldpi and not i mdpi. Let say we have phone with mdpi resolution density... What will happen ?
drawable folder is used for default images if the images are not found in the respective folders then it will look into the drawable folder.
I found this phrase in the doc:
For example, imagine you have an application icon, icon.png, and need unique version of it for different locales. However, two locales,
English-Canadian and French-Canadian, need to use the same version.
You might assume that you need to copy the same image into the
resource directory for both English-Canadian and French-Canadian, but
it's not true. Instead, you can save the image that's used for both as
icon_ca.png (any name other than icon.png) and put it in the default
res/drawable/ directory. Then create an icon.xml file in
res/drawable-en-rCA/ and res/drawable-fr-rCA/ that refers to the
icon_ca.png resource using the element. This allows you to
store just one version of the PNG file and two small XML files that
point to it. (An example XML file is shown below.)
Please refer this link for more clearity.
AFAIK you don't need drawable folder if you have all three types of folder (drawable-hdpi,drawable-mdpi,drawable-ldpi )with different resolution images.
As per I faced when you run the app on Android 1.5 and 2.0 if the images which is used in any layout is not available in folder 'drawable' then the project gives error "Resource not found" even if the image is present in other hdpi,mdpi or ldpi folder.
This is not about the densities there are other qualifiers as well, though in most of the cases we don't use them much. For list of qualifiers check here and here. You can use -finger -language ... etc qualifiers. In case you want to provide qualifier default resources[in this case drawable] you can opt for default drawable folder. Or many default folders without qualifiers added behind them
I think this page should help you understand better. Thank you for the question. I, myself, didn't know the answer. Basically you have 4 different versions and if no exactly matching version exists, the default one (without qualifier) is used.
Related
My android app requires over 1000 image icons to show in a image list view. I have all those images in a folder. I want to load all images from that folder and show them in an image list view.
But Drawable folder in Android offer following:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi
I found that there is no way to add a subfolder in any of these folders. Also, if I have to provide different resolution images for all drawable folders which seems complicated for me. I think then the app size will be multiplied by 4-5 times and I will also face difficulty to separate these image files with other images of the app. I think there is a better solution for it? Can you please give any idea about how to achieve it?
If you are ok with only having one size of the icons you can place them in the resource folder named drawable (without any extra qualifiers). I suggest you use a common naming scheme, like my_icon_XYZ.png, where XYZ is a number starting with 001.
I have read this article on mipmap before going through mipmap practically to understand its concept over drawable.
What i've faced is,
While working with mipmap layout-preview is not correct, while using image from mipmap folder.
Is mipmap only for launcher icon ? do i need to manually create all drawable folders(drawable-hdpi, drawable-mdpi etc.) for all other View's (Button, ImageView, etc.) image? If so then why don't android studio is not creating all drawable folder after creating new project?
I've also searched this issue but failed to get any useful or relevant link. I don't know what's wrong with mipmap because it seems fine while run code only layout preview is not correct.
Update :
Currently for workaround i've used mipmap folder only for launcher-icon and for all other Views i've manually created drawable-mdpi, drawable-hdpi etc.
to make layout-preview fine.
Please help!
According to this Google Post
The mipmap folders are only for placing your app icons.
Any other drawable resources(images and drawable .xml) you use should be placed in the relevant drawable folders as before Android 4.3.
This is the best practice to place your app icons in mipmap - folders (not the drawable - folders) because they are used at resolutions different from the device’s current density.
For referencing the mipmap - folders ensure you are using the
following reference: android:icon="#mipmap/ic_launcher"
You can also check the more about the Mipmap
Yes they are talking about the Launcher icon for the Nexus family. So this would be good practice if you do so. And for other resources you have to keep going in the same way As you always do.
I am new to Android and I need to use images in my XML file.
A tutorial says that I have to place them in drawable directory, but I can't find it as I find drawable-hdpi, etc.
drawable folder is divided into into three part according to device screen size h- high, M- Medium, L- Low because in android different size of device available in the market and android device screen divide into three type h,m,l based on density specific according to device size android pick the image from specific drawable folder h ,m ,l if you dont want to density specification in your application then add new folder with the name of drawable.
I hope it is more use full to you.
You can create the drawable folder yourself by right-clicking "res" -> "New" -> "Folder" and naming it drawable.If you do not need your images to be density-specific, you can put your images there.
you can create your own drawable folder in res directory. But remember keep the images in that folder which are common for all screen size devices. drwable-hdpi means this directory contained the images will be loaded when the device has higher dpi. similarly drawable-mdpi and drawable-ldpi are there.
Those which you found are drawable folders.. Insert the images in all three of them. So that at time of change in definition of screen images can be changed accordingly. For now, Insert same image in all three of them.
You can create your own drawable folder. But its good to use these at first then when you run your application on device you will come to know the difference.
drawable-hdpi drawable-mdpi etc are the different type of drawables . you can keep your images in these folder (any one at the initial level).
But they have some diffrence according to the resolution of the screen & density of android device. Further you can check the diffrence between them and keep the images as per need.
see this for more details: Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi
and Supporting Multiple Screens
you can create a drawable folder in the /res folder of your project and put your images there.
drawable-hdpi(mdpi/ldpi) are used separate different resources for different type of screen. take a look here to know more about multiple screen handling
I realize that this question is rather dated, but...it came up when I Googled the issue of inserting images into an Eclipse Android project, so....
Actually, those folders are mipmaps and they are used by the graphics subsystem to provide seamless zooming, as well. I would suggest creating proper mipmaps using an editor, as opposed to providing only one resolution choice.
I have some images in drawable-normal I can load them via
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), resourceId,
mBitmapFactoryOptions)
When I move the images over to drawable-large (and remove them from drawable-normal), then the images are not loaded anymore. There is no error, I just get null for bm. When I move them to drawable-hdpi or the like, they are loaded again.
Does Android handle the -small, -normal and -large folders different from the other resource folders? As described here, it should eventually load the images from the -large folder.
I guess I found the answer to my own question. Reading the aforementioned page more carefully, it turns out, that Android only searches the drawable-*dpi folders automatically, for all other qualifiers it only looks in the default folder if it does not find the resource in the more specific one.
In other words, if it does not find the resource in drawable-normal, it looks in drawable and then stops trying. It's only for the drawable-*dpi folders that android looks into all those folders. I guess I'll switch to these. Thanks to Tanmay for trying to help me.
I have not seen any drawable-large folder in your given link .
Android only supports drawable-ldpi,drawable-mdpi ,drawable-hdpi and drawable for storing drawable objects.
I have the following problem. From what I have seen if I put my resources in the drawable folder the sdk will scale them automatically if I don't have the anyDensity option in the manifest, but this does not look good on the Galaxy Tab (the icons look too small).
I have some specific resources for the 320x480, 480x800, 600x1024. If i put them in the specific drawable folders and not set anyDensity to true they look too big. If I set anyDensity to true they seem to look ok.
But the question is, if I don't have resources of different sizes for all the resources can i put some of them in the drawable folder (so the sdk makes the prescaling) and the other ones in the specific drawable folder or I need specific resources for all the resolutions and all the resources.
Thank you.
Yes. Android will select the most appropriate version of the resource to use at runtime automatically. So if you having one version of a picture in the drawable folder, and another in the drawable-hdpi folder, then the app will use the hdpi version if the device has a hdpi screen. If not, it will default to the version in the drawable folder. Just make sure the different versions have exactly the same name and extension. If you only have one version of a picture, it will always use that version. The -xxx extensions to folder names only override default resources.