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?
Related
I am researching best practices for working with layouts in Android projects.
In the Android documentation says that from Android 3.2 to create qualifiers type -mdpi -hdpi etc is obsolete and that the best way is to create specific folders for each screen as sw600dp and etc. Also talks to create different layouts for each case, but how are the dimensions and images in this approach?
I create separate layouts for each case with fixed dimensions in the layout itself? How is that?
Images continue in folders like "dawable-mdpi"?
I spent some time studying the documentation but doubt continues ..
https://developer.android.com/guide/practices/screens_support.html
Correct me if I am wrong.
Before Android 3.0 drawable were placed in folders depending on the screen size. For supporting larger devices, putting drawable according to screen density was introduced. With this drawable were chosen depending on the pixel density of the screen and not just the size of the screen.
You can read about it in "How to Support Multiple Screens" section of this page https://developer.android.com/guide/practices/screens_support.html#support
So I think using small, normal, large, and xlarge is depreciated and we now use ldpi (low), mdpi (medium), hdpi (high), xhdpi extra-high), xxhdpi (extra-extra-high), and xxxhdpi (extra-extra-extra-high)
And sw600dp, sw720dp etc are for devices with screen dimension at least 600dp, 720dp etc. You can read more about it here: https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
You'll find answers to all your question in the documentation you spent some time studying. Go through it again, and I am sure things will be a lot more clear to you.
I have one image that is in all folder except drawable-ldpi folder. Then if i will run my project in ldpi devices then from which folder it will try to find that image? or my app will simply get crash? I am not having this image in my drawable folder,too.
Test case i performed using mdpi device --
Placed image in drawable-xxxhdpi folder only, worked fine.
Placed image in drawable-ldpi folder only, worked fine.
Came to conclusion it perform both scale up and scale down
Regards
It is not required to have images for all the densities, only one is enough. The system will scale it up/down when needed. So the best approach is to have images for the highest density supported (xhdpi or xxhdpi).
It will scale but you might run into problems when a phone with a ldpi tries to load xhdpi or xxhdpi images.
Google's recommended that it is useful when you are creating different images for each resolution and not just resizing it.
And also in present when Eclipse creates launcher icons, it only creates them for mdpi, hdpi, xhdpi, and xxhdpi. Based on that creating ldpi icon is not necessary and that mdpi will be scaled down automatically.
In your case it will try to find image in mdpi folder.
Dont worry, FYI ldpi device is closed before some months and now no any new ldpi device will come in market. But if any user will install your app in ldpi device then it will find closest image as compare to ldpi and will show it.
But that image must be in any of the folder.
If the user is using a device with a low density screen, and a ldpi resource is not found, the resource with the closest density is used and scaled down.
By the way, I wouldn't even bother with mdpi, let alone ldpi.
Your app will not crash until you have the named image in at least one of drawable folders. System will show the closest density image.
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...
i am attempting to get my android app to work on both phone type devices and tablets. for the layouts i have layout-normal and layout-large and i place my xml files inside each and it seems to select the correct one for each device (layout-normal for phones and layout-large for tablets).
however the problem arises for the drawable folders. i have drawable-hdpi, drawable-mdpi and drawable-ldpi. the tablet is taking its images from the drawable-mdpi, and the phone is taking its images from the drawable-hdpi. from the reading i have been doing this seems to be backwards??? this seems to happen on both the emulator and real devices, could i be doing something wrong? am i mixing something up?
Clayton,
drawable-hdpi and drawable-mdpi is not related to the size of the screen itself, but to the resolution of the display.
It's probably easy to think in terms of the iPhone 3GS and 4 for this (bear with me please). The 4 has retina display, hence a much higher resolution. Using the same sprites you'd use with the 3GS would result in a blurry display.
Android phones are, if anything, much more diverse in terms of screen options.
If you want to be able to aim different layouts at different resolutions, please try putting the layouts into /layout-xlarge, /layout-large, etc...
You can find more here:
http://developer.android.com/guide/practices/screens_support.html
There are some changes that you can see for Android 3.2 and above:
Beginning with Android 3.2 (API level 13), the above size groups are
deprecated and you should instead use the swdp configuration
qualifier to define the smallest available width required by your
layout resources. For example, if your multi-pane tablet layout
requires at least 600dp of screen width, you should place it in
layout-sw600dp/. Using the new techniques for declaring layout
resources is discussed further in the section about Declaring Tablet
Layouts for Android 3.2.
ldpi, mdpi, and hdpi refer to pixel density, not screen size.
The accepted answer does not address a serious problem: if you have many drawables, you end up with an unnecessarily big apk file because of resource duplicating. The only solution for that is the resource alias option described here:
http://blog.evendanan.net/2011/03/Android-resources-and-device-fragmentation
Edit: I just beheld that OP didn't realize that most phones have hdpi density, while most tablets have mdpi density. At the same time the tablets mostly have higher resolution. Hence Android will use smaller pictures for higher resolution.
You can overcome this only by using vector images or using the methods described in the accepted answer and in my answer.
drawable-hdpi - application use this drawable images when the device has high pixel density
drawable-mdpi - application use this drawable images when the device has medium pixel density
drawable-ldpi.-application use this drawable images when the device has low pixel density
As per managing resources(images) in > Android 1.6 version, we need to keep different-resolutions image in Drawable-Hdpi, Drawable-Mdpi, Drawable-Lpi folder particularly.
And as per this page: http://developer.android.com/guide/practices/screens_support.html ,
In Low density section - there are three resolutions used: 240*320 , 240x400 , 240x432 for the Small screen, Normal Screen, Large Screen particularly.
same way for Medium density section - there are three resolutions used: 320x480 , 480x800 , 480x854 for the Small screen, Normal Screen, Large Screen particularly.
and same way for High density ........
but i am confused here:
(1) How do i come to know that whether small, Normal or Large screen is used, i mean is there any way to know ?
(2) How do i come to know which type of density i am using ?
(3) And in Drawable-Hdpi, Drawable-Mdpi, Drawable-ldpi folder, which resolution's image we should keep particularly?
There are specific Android API calls that can, at runtime tell you what density and (small/large/normal) screen size a handset has. However, as a developer we should not need to worry about individual handsets at all. All we need to do is to have ldpi/mdpi/hdpi assets and small/normal/large layouts in the apk. Android internally handles everything.
Dont forget to get an indepth understanding of how Android determines which assets to use and aliasing here.
Why do you want to know the actual density? It's Android's business. But I'm sure there is a way to retrieve this information.
For development I put everything in the hdpi-folder. I also could put everything in a general Drawable Folder.
At the time u publish u can decide if u want to provide already downscaled resources for ldpi and mdpi. However, thats not necessary.
Update: Retrieve actual density with this class and best practices
Update 2: I found a 25 min video from Motorola discussing all those issues: Working with multiple screens
1) Change the content of the layout in different folders i.e layout-small, layout-large, etc Now test it in Different emulator with different screen resolution.
2) For Finding out density of the Device use
Log.d("Density", "" + (getResources().getDisplayMetrics().density));