What is the difference between the three drawable folders in the res folder in the project hierarchy? If I have an image to put into a folder, which folder do I put it in?
I am going to take a guess that "the three drawable folders" are drawable-ldpi, drawable-mdpi, and drawable-hdpi. In that case, if you stick with all of those folders, you need to put one image in each, sized to match the indicated screen density. This is discussed in the online documentation as well as this blog post. You can find a set of sample projects showing use of different drawable resources based on screen density here.
If you are just starting out in Android development, you can get rid of all three of those directories and create a single drawable directory, putting your image in there. Eventually, though, for a quality application, you will want to test your images on different devices/emulators with different screen densities, and possibly have different images for each density to improve the look of your app.
Here is a reference to multi device options.
As said by #CommonsWare, you don't need to put resources in anything but res/ layout/ or drawable/ but if you want your program to have a better experience on multiple devices with different screens / density / languages you may want to consider that you have that option.
Also interesting, though not specific to images, is how android handles resources. It gives them a load order, where more specific means it'll get picked over less specific.
For example, you have three String values in strings.xml in your values folder. You also have one specific string in a folder called values-en. When android opens your app and your locale matches en, it will load two defaults from the values folder and the third, more specific string, from values-en. If your locale is ru, it will just use the default instead because you have no values-ru folder.
The same is true for images. If android can't find images for your specific screen variant, it will use defaults from the drawable folder.
In my opinion it's good practice to have default values/images in your generic folders like values/drawable and specific values/images in specific folders. This way both current and future devices will at least have a way to display your content until you can provide specific versions.
Related
I am just getting into an android project that someone else already worked on. I am currently just correcting UI issues and such, and we decided we needed bigger sizes of some graphics that look blurry on tablet size. So we decided to make a few size-dependent folders.
Until now, former guy has placed a lot of graphics into the mipmap folder because it automatically selects images based on density. But now i read that mipmap is only for the launcher icon.
Now my dilemma is whether I should move the graphics or not. It wouldn't be too hard to do, but i tried with a few, and I noticed that when taken out of the mipmap folder, and placed inside the drawables folder, the graphics are suddenly bigger. This means that I either have to resize every single graphic, or replace the file with a smaller version.
I am tempted to leave well enough alone, and not invoke all sorts of re-design processes for the sake of keeping the structure tidy. But on the other hand, it kinda hurts not to.
Does anyone know what I should do, or if mipmap is ok to use for graphics that aren't the launcher icon? And if I am to move it, how do I best tackle all these problems?
Ideally, you would have larger images which are then used accordingly in the relevant drawable folders. Android takes care of resizing these automatically. This is also the reason why the images you have in the minimap folder are being enlarged when exported to the other folders.
If I were you, I would leave the graphic files in the same folder as the previous developer set them. Otherwise you will be getting pixelated images.
The other option would be to use an image-editing software to enlarge the images and copy them to their respective folders.
In the end it is up to you, but if as you are saying, there are many images, I would leave them where they are.
mipmap is ok to use for graphic.in eclipse their are drawables folder to place images but in android studio project mipmap folders are default folder and you can put any type of images it will automatically adjust according to size but put 9paches image in that folder
before when I was creating a new project I was found this folders drawable-hdpi,drawable-mdpi, drawable-xhdpi, and drawable-xxhdpi. but now they are all gone!
is there any explanation of what happens?
and where we should put our images?
This is perhaps because they will add an Gradle plugin that converts SVGs to PNGs during build (as mentioned in this IO talk). The idea is that you will only need to have a single SVG instead of multiple PNGs for various densities (an thus, only one drawable folder). You can still create the folders and use PNGs.
The Gradle plugins for SVG conversion by Google has not been released yet, but you can use Victor or a similar plugin if you already want to use SVGs for your drawables.
You should read Android Blog
you can just create drawable-xhdpi.
I just give answer here
read and if any problem ask.
I wasn't aware that Android Studio ever provided these dpi dependent drawable folders for the built-in default project scaffolding, and indeed, why should they?
Are they supposed to guess that you're going to support each and every one of these resolutions? Perhaps all your graphics will be vector graphics? Perhaps you only target low or high resolutions?
Also, the DPI modifier is only 1 of the possible modifiers you can attach to a resource folder. You can also add locale, screen width / height, mobile country code and many more. Should Android Studio create a folder with each of these options, along with every possible variation? You'd end up with thousands of folders which you'd likely never use.
In addition, creating a folder with no assets inside it is a big problem when you start synchronising your code using Github or something similar, and creating every possible folder with default assets inside seems like a huge waste.
I think the best approach here is to create any resource folder you need when you need it. Google leaves this decision to you.
Also, important: There is no XDPI or XXDPI folder - it's XHDPI, and XXHDPI
Check in your project section, Not in android section, If they gone just simply create them
I have developed a game in android,but i'm facing many problems with the screen sizes I heard that we should create separate folders like(layout-small,layout-normal,layout-large,layout-xlarge) in the res folder and should maintain all xml files in them.
But my confusion is how to retrieve particular xml from particular layout folder what is the code should be written in the Activity..?
Please help me to solve this by an example.
Thanks
you dont choose from which folder you read the xmls. Android does it for you depending on the dpi and the size of the screen its running on.
This is what helped me:
http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html
I believe Android does it automatically. The operating system detects when the display is a certain orientation / size and uses the layout from the appropriate folder (if present) without you having to do anything apart from create the layout files.
No you don't need to create xml for each screen size.
store your xml in your layout folder.
and as per the size (hdpi, mdpi, xhdpi, xxhdpi) create images.(read developer guide for image size)
In android project there are multiple folders, I know you can simply override these with one 'Drawable' folder.
My question is: When people download my app, will it take up more room if I have manually catered to all the different Drawable folders instead of just overriding them with one?
yea, but your app will be slightly slower, cause android has to re-size the images (whereas if you have different folders it uses the respective images)
Yes, different Drawable is for different dpi based device screen and its part of APK.
When you download APK then even drawable is also part of it and it gets stored on device and it does take space.
Different Drawable folders in android directory is for supporting different screen sizes. for better UI experience you should put drawables in appropriate folders.I think you should have look into it before proceeding further Know android project directories
I see three folders within my eclipse project drawable-hdpi,mdpi,ldpi
Do I need to put images in all three of these folders?Or can I just use one of them.My images
seem to scale fairly well.I do not want to have duplicate images if it is uneccessary.
I guess what I am asking is will the app be able to find my images if I just use one of the above mentioned folders?
Technically if you drop them in mdpi, I believe all devices 1.6 and above will find them. However, if you support below 1.6 devices you'll need to duplicate the drawable-mdpi resources and call it just drawable.
Yes it will find the Drawables regardless of which directory you use. You can also just have a drawable directory if you don't plan to support different densities.