I tried making images folder but I cannot call it by using R.images.(filename) also, putting the images in raw folder does not solve the problem.
is there any way where I can use the images?
This is well explained in the Drawable Resources section of the documentation.
You'll end up with drawable-xxxhdpi and other folders. Put your my_image.png in those folders at the proper DPI levels and you'll be able to access those images with R.drawable.my_image.
If you need an easy image resizer library I have one over at https://github.com/jlindenbaum/res-resizer
Related
Button which i created for my app is of resolution 166*169. But it doesn't look perfect on my app when placed directly from drawable folder. So i created other drawable folders, but what is to be the resolution among them doesn't know. I do google that but nothing find which is relevant to me.
You need to create different png files for different drawables such as hdpi or mdpi. I recommend you do use 9-patch images. It is simple now that you can use a 9-patch generator, just put your image it will generate 9-patch images for all your drawable folders and you just need to import them.
Use SVG instead of PNG or JPEG in drawable, android support svg and this Link will help you
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 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.
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.