As a general rule, when storing image resources for use in an Android project, should they be placed in the res/drawable or the res/mipmap folder?
Apologies for the simple question, I'm relatively new to Android development. The IDE I'm using is Android Studio 1.0.
My rule is that if an image will have noticeable changes in quality when they are scaled up or down depending on the android device should be stored in mipmap folders. Examples of such images would be icons, slider bar scrubbers or custom google map markers. Images that don't get affected by changes in scale can be put in the drawable res folder.
The graphic resources are stored in corresponding folders “drawable”. A store application icons are stored in the folders “mipmap”. To make the icon you have to make the files with the identical name which will be differ by resolution only and will be placed in the correspondent folders “mipmap”. Here are the the dimensions in pixels for each screen density:
LDPI 36×36.
MDPI 48×48.
TVDPI 64×64.
HDPI 72×72.
XHDPI 96×96.
XXHDPI 144×144.
XXXHDPI 192×192.
When the screen density is not important, I create a simple “drawable” folder and I store there all images. If the screen density is important it is possible to calculate the dimensions of the image, based on the ratio of the size of the base image to the appropriate screen ratio. For the base density is taken MDPI (48 × 48):
LDPI — MDPIx0.75.
HDPI — MDPIx1.5.
TVDPI — MDPIx1.33.
XHDPI — MDPIx2.
XXHDPI — MDPIx3.
XXXHDPI — MDPIx4.
At the time of publication in the convenience store (play.google.com), you will need also 512 × 512 icon and picture for advertisment of 1024 × 500.
In the manifest, do not forget to register R.mipmap.your_icon_name (default R.mipmap.ic_launcher) and the system will automatically select the icon under the screen density
Images that don't get affected by changes in scale can be put in the drawable folder.
If you are building different versions of your app for different densities, you should know about the “mipmap” resource directory. This is exactly like “drawable” resources, except it does not participate in density stripping when creating different apk targets.
Provide at least an xxxhdpi app icon because devices can display large app icons on the launcher.
It’s 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.
Related
I'm new to android programming and every single somewhat-similar question is from three or so years ago and doesn't really answer my question. Android Studio used to have different drawable folders for different dpi. Now there is only one. So if I have two images with the same name but for different dpi, where do I add them so that during runtime the phone can use the appropriate image?
Also, most android phones now are xhdpi or xxhdpi--do I really need to include any images less than that? And how exactly would I do that? Say, for example, that I get an image off shutterstock. How do I make it so it works correctly for both xhdpi and xxhdpi?
Those folders have not gone anywhere, if you want them you simply create a new folder and name it appropriately ( drawable-xxhdpi etc.. )
Depending on IDE it just does not make them by default under certain circumstances
DENSITY SIZE LOCATION RATIO SCREEN MARGIN
XXXHDPI 192×192 drawable-xxxhdpi 4 640 DPI 12 to 16 pixels
XXHDPI 144×144 drawable-xxhdpi 3 480 DPI 8 to 12 pixels
XHDPI 96×96 drawable-xhdpi 2 320 DPI 6 to 8 pixels
HDPI 72×72 drawable-hdpi 1.5 240 DPI 4 to 6 pixels
MDPI 48×48 drawable-mdpi 1 160 DPI 3 to 4 pixels
MDPI 48×48 drawable (Cupcake) 1 160 DPI 3 to 4 pixels
LDPI 36×36 drawable-ldpi 0.75 120 DPI 2 to 3 pixels
NA 512×512 Google Play NA NA As required
Android Studio used to have different drawable folders for different dpi.
It still does.
Now there is only one.
No, there are several. However, in the "Android" project view, they are shown in a collapsed state:
If you change the drop-down towards the top-left of that screenshot to "Project", you will get the view that you are used to, that mirrors the filesystem:
So if I have two images with the same name but for different dpi, where do I add them so that during runtime the phone can use the appropriate image?
The same place as before. Personally, I find the "Android" project view to be singularly useless, and so I switch to the "Project" view as one of the first things when I open the project.
most android phones now are xhdpi or xxhdpi
No, right now, only about a third are.
do I really need to include any images less than that?
I would. If you have a zillion drawables, you are welcome to experiment with having fewer densities, but you will want to test the lower densities to confirm that the downsampling of your drawables is turning out OK.
Create the folders yourself as you need them. It's true that most phones now are xhdpi but what about your target audience? Are you sure their phones and tablets support xhdpi at minimum? There are some tablets such as the Galaxy Tab 2 which are below these values. Just something to keep in mind. Although, consider using layout-sw(x)dp for devices bigger than 600dpi
You'll have to resize them for the appropriate drawable. Use you should follow the 3:4:6:8:12:16 scaling ratio where 48x48 is the baseline. As an example, in order to support xxxhdpi your drawables would be 192x192
Actually Android Studio also has multiple drawable folders. But It remains wrapped in Project Structure's Android View.
So you see only one Drawable folder.
If you want to see all the drawable folders in expand mode then click on the drop down like below and select "Project":
Now you can navigate the drawable folders like this:
When I create my Android app i create 6 drawable folders:
drawable-hdpi. // resolution 1.5 x
drawable-mdpi. // resolution 1 x
drawable-xhdpi. // resolution 2 x.
drawable-large. // resolution 2 x.
drawable-xlarge. // resolution 2.5 x.
drawable-xxhdpi. // resolution 3 x.
In every folder i put the same image with different size according to android device resolution and screen size.
Is this correct? or this is insufficient for my android app ?
When i make project in Android Studio it automatically generates the folder structure for drawable- i.e
-- res
| -- drawable-hdpi (for low density screens)
-- drawable-mdpi (for medium density screens)
-- drawable-xhdpi (for high resolution screens)
-- drawable-xxhdpi (for extra high resolution screens)
The drawable-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
I think that the above is more than sufficient for an android application. And actually xxhdpi is more than enough for a high res tab or phone. Please go through Supporting Multiple Screens.
First, it's not necessary to put all the same images with different size in every folder. If you put the full set of images in drawable-xxhdpi folder, the system will re-size the image for other density automatically. Sometimes, some image may lost important details while re-sizing, then you should redesign a proper image for the density and put in the corresponding folder, not ALL images.
Second, xlarge/large/normal/small are the size of screen, ldpi/mdpi/hdpi/xhdpi/xxhdpi are the density of screen, the resolution is the combinations of size and density.
Finally, you may prepare just one set of image in res/drawable-xxhdpi folder, then design different layout for different screen size in res/layout-*** folders, just set different dp in width/height/margin etc..
Reference: https://developer.android.com/guide/practices/screens_support.html
This question already has answers here:
Android screen size HDPI, LDPI, MDPI [duplicate]
(4 answers)
Closed 9 years ago.
I have to manage different screen sizes and different densities in my Android app.
I am not getting directory structure properly.
What I understand so far is there are four types of screen sizes:
small
normal
large
xlarge
and different densities as well:
ldpi
mdpi
hdpi
xhdpi
Now each device size (small , normal , large and xlarge) shall map against each density. Because every size can have different density, right?
If yes, then we can say small screen have all the density i.e ( ldpi , mdpi , hdpi , xhdpi)
same for normal, large and xlarge.
The point is how I'll manage them in my drawable directories.
Will there be four folders for small screen size with different size (drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi)?
And same for other screen sizes as well.
If not then how I'll manage all the image in ( drawable-ldpi , drawable-mdpi , drawable-hdpi , drawable-xhdpi) folder because different screen size I'll have different size of images. Then how can a small device with different density and large device with a different size be manageable in same density folder.
Please don't give me reference of any Android document as I read all that stuff.
If any one can't get my point, then please let me know. I'm very confused.
When I have started development in Android, I was confused about same issue.But now I have figured it out and I'm doing pretty well.
Anyways, You are absolutely right.you can provide different images by 4 folders for each.i.e.: drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi
But it is just waste of your time.because you don't need to worry this much about it.Android can scale up/scale down according to the device configuration.so just provide extra images for those devices only if you don't get desired outputs for them.
As far as I know, supporting multiple devices, you have to consider few general criteria in your mind.
Density qualifiers: ldpi,mdpi,hdpi,xhdpi,etc are generally used when you want to provide different resolution images.
Size qualifiers + Orientation qualifiers: small,normal,large,xlarge,sw600dp,normal-land,normal-port,etc are generally used when you want to provide different layout designs.
i.e.: single pane layout,multi-pane layout,different elements in layouts according to different screen sizes.
For reference: Download the example app from here and try to understand how it is being supported for multiple screens.
I hope it will be helpful !!
Here are official docs for you to read about the subject: Supporting Multiple Screens then Supporting Different Screen Sizes
Put your all image in all different folder that is drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi and drawable-xxhdpi. android will take care of it.
What I always do is just put all my images in one folder (usually xhdpi). The Android system will scale them for you so you don't have to worry about what to put in what folder.
Heres what Android says about this:
Provide different bitmap drawables for different screen densities
By
default, Android scales your bitmap drawables (.png, .jpg, and .gif
files) and Nine-Patch drawables (.9.png files) so that they render at
the appropriate physical size on each device. For example, if your
application provides bitmap drawables only for the baseline, medium
screen density (mdpi), then the system scales them up when on a
high-density screen, and scales them down when on a low-density
screen. This scaling can cause artifacts in the bitmaps. To ensure
your bitmaps look their best, you should include alternative versions
at different resolutions for different screen densities. The
configuration qualifiers you can use for density-specific resources
are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high).
For example, bitmaps for high-density screens should go in
drawable-hdpi/.
You can find the documentation here:
https://developer.android.com/guide/practices/screens_support.html
Hope this helps
I am working on a Android Project.
I put the images (320*480) into the mdpi -folder. There are some information in Android developer site that 480*800 tablets(7") also takes images from the mdpi- folder. When the 7" tablet takes images form that mdpi- folder it become smaller. There is only one mdpi- folder so how do i exactly manage it .
You should read the Android developer documentation on Providing Alternative Resources.
From my answer to this similar question:
The ImageView will render the image inside of it at the correct resolution for the device. As per the documentation on providing resources, you must make sure that you provide resources at the correct DPI for each of the resolution types. Android will pick the best resource resolution for you, but if only one resource exists then it will pick that one and try to render at the device resolution.
So, find out the correct DPI for your device, and add the image (at the correct DPI) into that folder and it should appear at the correct size. If the image is placed in the wrong folder then it will appear a different size. Another useful link is the Density Independence documentation.
Note: let's assume your device is an HDPI device. The res/drawables/drawable-hdpi folder might not exit in your project but you can just add it in manually.
Don't mix up screen size with screen density. There are qualifiers related to screen size (e.g. small, normal, large, ...) and qualifiers related to density (e.g. ldpi, mdpi, ...).
You can even combine these qualifiers, for example in drawable-normal-mdpi you can put resources that will be used on devices with normal screen (phones) with a mdpi density.
you should create ldpi, hdpi, xhpi folder too. And you need to copy your image with same name by calculating its ratio.
ldpi - mdpi - hdpi - xhdpi
3 4 6 8
There is a 3:4:6:8 scaling ratio between the four primary densities
(ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in
mdpi, 18x18 in hdpi and 24x24 in xhdpi.
If you decide that your image resources don't look good enough on a
television or other certain devices and want to try tvdpi resources,
the scaling factor is 1.33*mdpi. For example, a 100px x 100px image
for mdpi screens should be 133px x 133px for tvdpi.
I have created four versions of my launcher icon for ldpi, mdpi, hdpi and xhdpi devices. They are of dimensions 36x36, 48x48, 72x72 and 96x96.
I'm wondering what will happen when using a large screen. Consdering large screens are rouglhy 7" + in size a ldpi, large screen will surely not want a 32x32 icon image, located in a drawable-ldpi folder.
I cannot find anything on the dev guide that indicates what icon sizes to assign to large and xlarge devices. Presumably I would put a larger copy of the icon in the drawable-large and drawable-xlarge folder. However, I do not know what sizes to use. Does anyone have any recommendations?
Google provide an online tool called Android Assest Studio which creates the launcher icons in the correct size for you. http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html
A 7-10" tablet doesn't need anything unusually large. You don't need anything bigger than a 96x96 launcher icon for this use case. There is a table in the Launcher Icons section of the design docs that shows which sizes correspond to which densities.
Have a look at the Declaring Tablet Layouts section of the design docs for more info on how to organize resources for 7-10" screens. (Note that the resource used will depend on the screen density, it is possible that a 7" tablet will have an mdpi screen.)