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.
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.
For support multiscreen devices android, typically using a drawable-xhdpi, drawable-hdpi, drawable-mdpi, drawable-ldpi for resources images. For using it with assets folder how to implement it? Do I need to create separate folder like assets-hdpi, assets-mdpi? Or what?
Assets folder is the folder using for stored raw data/resource such as media/audio files, text file or html ... which can be used for every screen size/density.
For support multi screen you only need to develop different layout/drawable file and put them into corresponding folder as you said above and don't need to make different raw data for multi screen.
No. You can't create such folders. But you can name your files different names (this example is for fonts) e.g:
font_for_large_screen.ttf - for big screen
font_for_small_screen.ttf - for small screen
and then have this strings in res -> values . As you may know, you can differentiate string values by screen sizes (and other characteristics). So, on on hdpi screen font value will be :
font_for_large_screen.ttf
on small :
font_for_small_screen.ttf
and you can grab appropriate font (or other file) from assets. Hope this will help you.
in my android application I've the same image in both the drawable folder and drawable-hdpi with different names (svs.jpg and svs1.jpg)
First, I've used svs.jpg (drawable folder)
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/svs"
/>
In one system it runs without any hindrance, but it shows error in another system (Inflate exception error in binary xml file). So I've used the image svs1.jpg as android:background="#drawable/svs1". Now it is working..
If I use svs1.jpg on the first system it shows error. I don't understand this problem. Can someone say why is this happening?
Images in different resource folders are meant to get the same name so the device will choose the one to use.
If they don't, I suppose some device are looking for the image name in the 'drawable' and crash if they don't find it, other device will look in the 'device-hdpi' folder and crash if they don't find it.
more information on supporting multiple screen here.
It seems you are really misunderstanding what these folders do.
Your android will select folder based on it's screen size or pixel-density of device on which u run it
If Your device has a medium Pixel density and a large screen. So it selects its resources from the res folders with those given qualifiers.
res/layout-large/my_layout.xml
and images from
res/drawable-mdpi/my_icon.png
You cannot tell your device to get images from the hdpi folder because it does not have a high pixel density.
So u give name of image same in all drawable folders .. Your device by default ll decide from which folder to take image , you need not worry about tat.
and just make sure the right images are in the right folders.
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 newbie as far as android application development is considered.
I am little bit confused about drawable folders.
In the tutorials available on the android developer site they have mentioned about the drawable folder. But when I create android 2.3.3 application I see three folders drawable-hdpi, drawable-mdpi and drawable-ldpi.
I know that this for screen resolutions. If I have an image as a resource I have to create equivalent three images with different sizes and put these images into these three folders.
But for example, I am working on a localization (German) with images. Should I create folder drawable-hdpi-de-rDE similarly drawable-mdpi-de-rDE and drawable-ldpi-de-rDE or should drawable-de-rDE be sufficient?
If drawable-de-rDE is sufficient what will happen if it is run in mdpi or ldpi?
Please clear my doubts regarding this.
Thanks
Pankaj
Should i create folder
drawable-hdpi-de-rDE similarly
drawable-mdpi-de-rDE &
drawable-ldpi-de-rDE
If you want to make your pictures (at the right sizes) yourself, yes, you'll have to create directories that are specific to both the culture and pixel density. However, the culture should come before the dpi, or the project will not compile. For example, the following would compile correctly:
drawable-de-rDE-hdpi
drawable-de-rDE-mdpi
drawable-de-rDE-ldpi
should drawable-de-rDE will be
sufficient?
If you don't feel the need to draw your pictures at the right scale yourself, that should work : android will scale the images to the right size, as needed.
But note that you might get better graphics doing that scaling yourself -- and, instead of just scale up/down, you could re-think your images a little bit, so they fit better in different sizes.
http://developer.android.com/guide/topics/resources/localization.html