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
Related
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.
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:
I am in the process of creating layouts for a new application and I am interested to know how you are usually approach this process.
Obviously it's a very general question, but I think we can get a lot of ideas from different developers' perspectives. As creating perfect layouts in Android, in my opinion, is one of the most difficult tasks in the app development process, I think the answers can be of value.
The assumption is that we want to support all device sizes with the least number of XML files, without compromising the application design quality.
In my case the designer of the app designed it with Galaxy S3 dimensions in mind (720 x 1280px).
Considering the 3:4:6:8 ratio -
What will be the base device you'll do the design for, so one layout file will look good on all normal size devices?
How would you handle the difference in device dimensions, thinking in dp -
Eg.
480 X 800 hdpi = 320 X 533dp
320 X 480 mdpi = 320 X 480dp
720 x 1280 xhdpi = 360 X 640dp
How will you still use the extra dp, so there won't be to many empty spaces, without making the layout not appropriate for 320 X 480 device?
When the designer marks a margin of 20px, how would you interpret it in the xml?
Taking into consideration he designed it on a 720 x 1280px canvas.
Start with some screen size as your base target device for e.g. 4.7 inch (hdpi) and create a single layout for default screens in layout folder and declare dimensions in dimens.xml in values folder.
Next, let's say you want your layouts for a 7" device, create values-sw320dp folder for 7" in portrait orientation and declare separate dimensions in dimens.xml in this folder.
Next, let's say you want your layouts for a 10" device, create values-sw720dp folder for 10" in portrait orientation and declare separate dimensions in dimens.xml in this folder.
PS: For landscape orientation, add -land in the end of folder names.
Next, let's say you have new devices such as xhdpi and xxhdpi devices, you can create values-xhdpi and values-xxhdpi folders.
Since you have defined dimensions in values folder, when you run the App, most of the dimensions will be used from here only. And you can add/update the dimensions in respective folders for screen-size and resolutions on which there is any mismatch.
Also, if you have got separate drawables for various size like mdpi, hdpi, etc you can place them under drawable-mdpi, drawable-hdpi, etc.
The Android system will take care of loading correct resources at run-time.
Note: On Android versions < 3.2, the folder naming was little different, you can refer that here.
Hope this helps.
Android automatically scales layouts to fit the current device. One way to make the solution more elegant would be to create separate folders drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi to hold the drawable resources - this is to make sure the same resource does not get used across all the different resolutions where it might not be so clear.
Do not use px (pixels) for measurements in the layout file - use dip (or density independent pixels) which allows to scale according to device pixel density.
The other extreme would be to have different layouts for different resolutions though this is is not advisable.
I am having the following specification images,
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Both in portrait and landscape. These are stretched in Tablet. But working fine in mobile. I am handling the configuration changes using the onConfigurationChanged() override method. Is any other way for giving the images for Android application. I reffered the following link for screen sizes. http://developer.android.com/guide/practices/screens_support.html
you can use drawable-large for tab
Following crocboy link is correct, and i suggest you to try including more buckets on your app. For example, in my applications i use also this:
drawable-sw600dp-mdpi
drawable-sw720dp-mdpi
In this buckets, put images that match tablets screen, for example in drawable-sw600dp-mdpi insert a background with this size 1280x800 and for drawable-sw720dp-mdpi a background with this size 1920x1200.
It's quite difficult to decide wich tablet to target, because we have different screen size.
EDIT
"application have to support all devices. So, the drawable folder images also have to support for all the devices. How to achieve this?".
Basically Android create this 4 folder for drawable:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
(To be picky, low drawable-ldpi is not quite used, because small device are loosing appeal)But due to density and screen size you can have:
drawable-large-mdpi
drawable-large-hdpi
drawable-large-xhpdi
drawable-xlarge-hdpi
drawable-xlarge-mdpi
And so on with various combination! If you are looking for image perfection (like my graphics collegue, wich is an iOS psychopath) you have to create images for every type of screen, and put it on relative drawable bucket.
In the same link ("How to Support Multiple Screens"), they tell you how to create seperate drawable folders for each resolution - such as drawable-hdpi. When the system detects a high-resolution screen, it takes drawables from the high-density folders. You can also do the same with layout folders. If it's a low-resolution screen, it uses only images from the low-resolution images folder, drawable-ldpi. Here is also a good article article about how Android picks images from these folders.
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.