I am brand new to Android and I am using Eclipse ADT to create a simple application. This application has a button that changes it's background image based on user clicks.
I noticed that there are 4 folders for images in my project: drawable-hdpi, drawable-ldpi, drawable-mdpi, and drawable-xhdpi.
and I also noticed that the images that are in there currently (the launcher icon) are all different sizes.
Does this mean that I have to use some image editing software to create one image for each resolution for each of my images? Or (hopefully) is there a way to import an image and have this done for me automatically?
Thanks!
Images and other visual files are stored in one or more drawable directories. If only in one directory, Android will scale the image as needed. If more than one directory is used, Android will select the appropriately sized image.
drawable-ldpi - Low density images
drawable-mdpi - Medium density images
drawable-hdpi - High density images
drawable-xhdpi - Extra high density images (i.e. retina-like displays)
drawable-xxhdpi - Extra extra high density images (devices like Nexus 10, Samsung Galaxy S4, HTC One and Sony Xperia Z)
drawable-xxxhdpi - Triple extra high density images (Nexus 6 and 9)
(Side note: XML files can also be written and stored as drawables. These kinds of files can control when multiple images are to be used based on the state of a view, or other visual settings like gradients, borders, etc.)
So, what should you do?
For best results (from the Android developer docs):
To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:
xxxhdpi: 4.0
xxhdpi: 3.0
xhdpi: 2.0
hdpi: 1.5
tvdpi: 1.33 (TVs only)
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 133x133 for tvdpi, 100x100 for mdpi, and finally a 75x75 image for ldpi devices.
If you just want to use one image and let Android scale for you:
More than 75% of Android devices now have hdpi or greater resolutions, according to the Dashboard on the Android Developer site. So if you create one image at hdpi, for example, it will look perfect on about a third of devices, scale up for some, and scale down for about 25% of devices. In general I think you'd be better off scaling down than scaling up, too.
Does this mean that I have to use some image editing software to create one image for each resolution for each of my images? Or (hopefully) is there a way to import an image and have this done for me automatically?
If you already have high resolution sources (or vector graphic formats) of your images, you can use the Android Asset Studio to generate icons/images from your own source images for every density (minus xxhdpi). You can also create icons/images from default Android clipart, that can be themed for various versions of Android. This will save you some of the hassle of resizing and saving with an image editing tool.
Related
As you know Android applications have different DPIs and also in the Android applications we can add drawables with diffrent DPIs in diffrent ldpi, mdpi, hdpi and xhdpi folders.
The question is that when we want to support all DPIs we should add the icons with all different sizes or just with the biggest one?
I mean for example suppose that I have one action bar item with icon. Whether I should add the icon of this action bar item with 24x24(in drawable-mdpi folder),36x36 (in drawble-hdpi folder),48x48 (in drawable-xhdpi folder),.....
Or I just need to add one icon with size 96x96 in xxxhdpi folder and android will set the icon for other DPIs with good quality?
TLDR see the bold below
Different density folders were added later on for Android which means that...
If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.
If you want to have complete control over how the assets are scaled then you can by all means provide your own for all / some of the densitys. In practise I generally provide HDPI / XHDPI as above and give all the resource buckets for things like logos / AB icons / App icons etc. I generally find the auto scaling to be pretty good and work for most situations, but will occasionally have to supply and extra LD/MD asset if its a small asset / contains small text etc. Plus if i duplicated all assets for things like XXXHDPI I would get pretty good apk bloat.
You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.
I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.
It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.
Taken from the link below
ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. This qualifier was introduced with API level 13.
List taken from this dev link for more info.
This is the approach I have used on many apps in my professional career including ones for Google & the BBC and not had issues.
I'm gonna release my app, it's a 1.2Mb apk that includes about 120 icons in 4 different formats (ldpi, mdpi, hdpi, x-hdpi).
If I add xx-dpi and xxx-hdpi icons the apk grows bigger and loading time increases.
There are many entry-level devices out there with really loooow memory and I'd like my app to run everywhere.
Do I really need to add xx-hdpi?
And is there a real device that requires xxx-hdpi?
You shouldn't really need xxxhdpi. It was only introduced because of the way that launcher icons are scaled on the nexus 5's launcher
Edit
Back when I answered in Jan 2014, the Nexus 5 was the only device using xxxhdpi. Now many devices including the Nexus 6 and LG G3 use it. So it would be a good idea to include it in your app.
We had to add xxxhdpi to our app for the Nexus 6, LG G3, and Samsung Galaxy Note 4. There will be more xxxdhpi devices in the future.
You do not need xxxhpdi for most of your images. You only need xxxhdpi for your launcher icon. Please see http://developer.android.com/guide/practices/screens_support.html
You should not use the xxxhdpi qualifier for UI elements other than the launcher icon.
It's pretty clear in the above quote. In the example folder layout they give, they show all the densities for the res/drawable folders up to -xxhdpi, but then they show the res/mipmap folders up to -xxxhdpi. Here are more quotes:
xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi). Use this for the launcher icon only, see note above.
The mipmap-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.
You don't need ldpi, because Android downsizes hdpi to ldpi.
From https://developer.android.com/design/style/iconography.html
Note: Android also supports low-density (LDPI) screens, but you normally don't need to create custom assets at this size because Android effectively down-scales your HDPI assets by 1/2 to match the expected size.
From Android iconography documentation itself:
Some devices scale-up the launcher icon by as much as 25%. For example, if your highest density launcher icon image is already extra-extra-high density, the scaling process will make it appear less crisp. So you should provide a higher density launcher icon in the drawable-xxxhdpi directory, which the system uses instead of scaling up a smaller version of the icon.
Note: 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.
more on: http://developer.android.com/design/style/iconography.html
I don't know if there is a device that requires xxx-hdpi, but xx-hdpi is not yet used very often. But the same goes for ldpi, almost no device still requires ldpi. If you just do mdpi, hdpi and xhdpi, it will be just fine. If a device requires something bigger or smaller android just scales it to the right size.
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 think you should focus on the most popular screen densities, which are hdpi, xhdpi, and xxhdpi. See this link for the current worldwide average distribution of each density.
Forget Everything & make it Simple !
Just store highest resolution images in only one folder. Either in drawable-hdpi, & delete other images from the rest drawable folders.
I have tested it in various devices & it works like a charm...
So I am learning how to program android apps, and have just barely started. Looking through the developers page I followed a tutorial to add a search bar in the menu. However, it asked to put an image in the res/drawable folder. Upon seeing all these options I just placed it in the first folder, drawable-hdpi, and the app worked. I was just wondering if anyone could explain what the difference in each folder is, and if the icon is placed in the correct folder (even if the app still runs). Whats the most optimal solution?
http://imgur.com/t2r6fS2
Android Tutorial: http://developer.android.com/training/basics/actionbar/adding-buttons.html
Edit: Wow! Thanks for all the responses. You guys are fantastic. I'll mark an answer as soon as it will let me.
The folder names need to be :
/drawable-ldpi For low density screens
/drawable-mdpi For medium density screens
/drawable-hdpi For high resolution screens
/drawable-xhdpi For extra high resolution screens
/drawable should be reserved for assets that you don't either care which device or for xml drawable assets
Then on top of that you can provide different resources based on configuration by using config qualifiers, you can read all about it here http://developer.android.com/guide/topics/resources/providing-resources.html
for instance, you can have high resolution assets for landscape with a folder
/drawable-land-hdpi
Hope that helps
Android devices comes with different screen sizes and different resolutions. To support your application's images with different device's screen size you need to put your image in their respective folders. Following are the screen size supported by Android devices
LDPI ( deprecated )
MDPI : 48x48 Pixel
HDPI : 72x72 Pixel
XHDPI : 96x96 Pixel
XXHDPI : 144x144 Pixel
TVDPI
You can create such sizes images by helping of this site Android Asset Studio
These different folders are for different screen sizes. Here is a link to the android notes, http://developer.android.com/guide/practices/screens_support.html .
In short the ldpi is for low resolution screens, mdpi for medium resolution and so on.
Android different Screen size with different resolutions:
- drawable-ldpi (it need resolution or ppi is ~120)
- drawable-mdpi (it need resolution or ppi is ~160)
- drawable-hdpi (it need resolution or ppi is ~240)
- drawable-xhdpi (it need resolution or ppi is ~320)
If you create big images but less ppi then it will go in this manner. So be aware about this.
this may help you ....
check out the answer in below link
What is the difference between "px", "dp", "dip" and "sp" on Android?
My Android application is not loading the correct graphic images when running on a Galaxy tab 1.0. They look blurry and slightly pixelated.
My guess is that it is loading the images from the mdpi folder, because the device density is 1.0, but they are small for the tablet screen.
What should I do in this case? I don't want to increase the size of the images in the mdpi folder, because I have tested the application in a fair quantity of emulators and devices and it worked well, but I still want a way of loading bigger images for the tablet.
The device model is GT-P7510 and Android version is 3.1. The density of the device is 1.0, which I got using the code:
getResources().getDisplayMetrics().density
I have different image sizes placed in the folders:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
I am developing in API level 8, platform 2.2.
Thanks!
you should probably create
res/drawable-large-mdpi/
and put resources for large screens there. Instead of large you may evaluate to use other qualifiers, such as drawable-sw600dp,
see http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch
I need to run my application on multiple devices with diffrent specs.
Now I'm trying to get it work on just two: Samsung Galaxy tab p100 and Galaxy tab 7.0 plus
the differnces I'm care about now are dpi,the first device is 240 dpi the second is 170 and the version the first runs 2.2 he later 3.2
first I put the Images on the hdpi folder images on 7.0 plus is smaller and ugly so I copied them to mdpi folder works fine but this would double the size of my APK.
Is there any way to make android auto fit Images without the need to copy Images?
If you want that images look fine in either the device you have to provide the same images for mdpi and hpdi at differente resolution (see Alternative drawables).
However if you put all you images in mdpi directory only, Android will scale theme for hpdi screens. Remember also you have to use dp and not px for all your dimensions (see Density independence).
You can also be interested in how Android pre-scale and auto-scale resources (see Additional Density Considerations). If you want to force auto-scale, you can add this line in your AndroidManifest.xml:
<supports-screens android:anyDensity="false"/>