android resources folder naming - android

So i have a very stupid question. I am new to Android and trying to understand how the resources folder work.
I see that I need subfolders with ldpi, mdpi, hdpi, xhdpi, xxhdpi naming but does the naming of the actual image need to be different?
For example, If I have an image names icon.png.
In iOS: mdpi would be icon.png, xhdpi would be icon#2x.png and xxhdpi would be icon#3x.png.
Do I need to give different naming in Android?
If I put icon.png in 5 different folders with 5 different sizes, would there be a name conflict?
It would be very good if someone can explain it.
I read all standard android explanations but I want to make sure with someone who has actually done it.
Thanks for your time.

Directory Naming:
You do not need to provide a different suffix to your image file name for different screen sizes in Android like you do in iOS. The file name should be exactly the same for all the images of different sizes.
However, you need to follow Google's guidelines/conventions for directory naming. Images are called 'drawables' in Android.
Under the 'res' directory, place each image under a directory called drawable-<suffix>. Replace the <suffix> with the screen density qualifier (i.e., mdpi, hdpi, xhdpi, xxhdpi etc.)
Google recommends that you also create a directory called drawable (with no suffix) for default images. These default images will be used as fallback when Android does not find a specific image size for the user's device.
Example directory structure:
res/
drawable/
icon.png
background.png
drawable-mdpi/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
drawable-xhdpi/
icon.png
background.png
drawable-xxhdpi/
icon.png
background.png
Image Size Ratios:
The correct way to create images for different screen densities is by starting at a base image size for mdpi.
Say for example your base icon size is 48px x 48px. Then:
mdpi: 48px x 48px (1x)
hdpi: 72px x 72px (1.5x)
xhdpi: 96px x 96px (2x)
xxhdpi: 144px x 144px (3x)
xxxhdpi: 192px x 192px (4x)
References:
Directory structure:
http://developer.android.com/guide/topics/resources/providing-resources.html
For size ratio comparison (mdpi vs hdpi vs xhdpi vs xxhdpi) go to:
http://developer.android.com/design/style/iconography.html

Related

Multi Resolution background images in Flutter assets

In Android we have variety of dpi drawable folders so we add background images in that based on resolution. Same like in iOS we add in 1x, 2x and 3x based on screen sizes. But how we will add multi resolution images in Flutter assets?
Ex:
Android
drawable-hdpi
- login_background.jpeg
drawable-mdpi
- login_background.jpeg
drawable-xhdpi
- login_background.jpeg
drawable-xxhdpi
- login_background.jpeg
drawable-xxxdpi
- login_background.jpeg
How we add multiple drawables in flutter to support multiple screen sizes without image stretching or scaling?
Flutter defines ratios like ios so, for example, you can create a folder named 0.75x under the assets/images for ldpi images. Other densities are as below
Dentisity Flutter pixel ratio
ldpi 0.75x
mdpi 1.0x
hdpi 1.5x
xhdpi 2.0x
xxhdpi 3.0x
xxxhdpi 4.0x
See documentation here
How Flutter handles multi-resolution images is explained here.
It comes basically down to this:
AssetImage understands how to map a logical requested asset onto one that most closely matches the current device pixel ratio. In order for this mapping to work, assets should be arranged according to a particular directory structure: (...)
An example:
.../my_icon.png
.../2.0x/my_icon.png
.../3.0x/my_icon.png

How to add images to corresponding folders in res/drawable/

https://developer.android.com/training/basics/actionbar/adding-buttons.html
The icon attribute requires a resource ID for an image. The name that follows #drawable/ must be the name of a bitmap image you've saved in your project's res/drawable/ directory. For example, "#drawable/ic_action_search" refers to ic_action_search.png.
how to add image to res/drawable/ ?? What size image needed for each type, like xxxdpi,xxdpi
For your First Answer Please Visit Android ImageView example.Copy the image and paste into Eclipse/Android-Studio in the res/drawable directory.
The image name should be in lowercase, otherwise it will end up with
an error.
You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low, medium, high and extra-high density. This helps you achieve good graphical quality and performance on all screen densities.
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:
xhdpi: 2.0
hdpi: 1.5
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, 100x100 for mdpi, and 75x75 for ldpi devices.
Then, place the files in the appropriate drawable resource directory:
Project/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png
Any time you reference #drawable/awesomeimage, the system selects the appropriate bitmap based on the screen's density.
For more details
http://developer.android.com/guide/practices/screens_support.html
Reference
You should consider mdpi as you base and using that you can create for hdpi, xhdpi and so on
eg. if you mdpi size is 12px X 12px then for hdpi it should be 18px X 18px as hdpi is 1.5 times mdpi
use this link
About Android image and asset sizes
Drag drop image using finder/explorer
Use android design guidlines for icon size ratios
Just copy your images from your syaytem to drawable directory of your project
And for icon sizes you can refer to this answer
https://stackoverflow.com/a/12768159/4211264
What size image needed for each type, like xxxdpi,xxdpi
for icon size.. please refer this site
http://iconhandbook.co.uk/reference/chart/android/
Go to YourProjectName/res/drawable and save your image in this folder.
If u have different sizes you can also use the different drawable folders.
If it is one image for every size just create the new folder "drawable" and save your image there.

choose the correct dpi folder to put 32px x 32px and 36px x 36px in android

I want to put the icon on drawable folder. I see on this link , I can put the icon that have 36px x 36px in drawable-ldpi. But, I feel confused to put the icon for 32px x 32px. Where I should put that icon?
From the developer-document:
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.
I suggest you to enlarge 32 px icon to 36px and then either keep it in ldpi folder or keep 72x72 resolution images in hdpi folder.
Enlarge 32 px icon to 36px and then either keep it in ldpi folder or keep 72x72 resolution images in hdpi folder as #illegal-argument suggested below is the snapshot of project explorer, as you can see you can find ldpi and hpdi inside res folder

Android Application Background Resolution

I want to design a background for android application using Photoshop , let's say I have Samsung S4,So I set the resolution to the maximum of that device which is 1080x1920 and 441dpi
Now,my question is where should i insert it in what subfolder of Resources and depending on what we choose that folder
-drawable-hdpi
-drawable-ldpi
-drawable-mdpi
-drawable-xhdpi
-drawable-xxhdpi
What image feature decides on which folder image should be in?
Hopefully, this image will show you which category it falls into:
As you can see everything larger than 400dpi is xxhdpi, so you should place it there.
Also check out the DisplayMetrics page.
EDIT: To answer your last question. There isn't any image feature that determines where it belongs, the folders are simply used to load images with different resolutions onto different screens. For example if the picture containing text has high resolution and you place it on a low density screen, the text would be (physically) too small to read. So you place a higher resolution image in hdpi or xhdpi folder and resize it so it has smaller resolution and place it in ldpi and mdpi folders.
Please refer to this, it is from google!
http://developer.android.com/training/multiscreen/screendensities.html
You should put on drawable-xxhdpi folder.
A brief explanation about the drawable resources:
The drawable resources are, by default, divided in 6 generalized groups based on its pixel density:
ldpi: Low density drawables (~120 dpi)
mdpi: Medium density drawables (~160 dpi)
hdpi: High density drawables (~240 dpi)
xhdpi: XHigh density drawables (~320 dpi)
xxhdpi: XXHigh density drawables (~480 dpi)
xxxhdpi: XXXHigh density drawables (~640 dpi)
The scaling ration between these drawables should be 3:4:6:8:12:16
You only need to provide density-specific drawables for bitmap files (.png, .jpg, or .gif) and Nine-Path files (.9.png). If you use XML files to define shapes, colors, or other drawable resources, you should put one copy in the default drawable directory (drawable/).
Even if you don't provide alternative drawable resources for the different groups of density, the Android system will find the best matching drawable and scale it for you. But is recommended to provide alternative drawable resources in order to ensure to always have smooth drawables in all devices.
You might want to take a look here.

xdpi image of ldpi in android

I have a high quality icon. I copied that to drawable-xdpi folder. Can I use icon in drawable-xdpi for low density screens without creating drawable-ldpi folder?
Think it's drawable-xhdpi folder. Yes, Android will look for drawable in the folder that best fits the display type. If it is not found, it will try to determine the next best to use.
yes. Do not put that icon in drawable-ldpi folder.
If your app runs on ldpi device and OS does not found the resources in drawable-ldpi. Then it will use resources from drawable-xhdpi after scaling.
UPDATE
Quality will not be the same..as it is ldpi device.
It will calculate the resolution of new Image like this
resolution of xhdpi icon = x * y
resolution for ldpi will = x/2 * y*2
Why dont u put the image in MDPI or just drawable Folder ?

Categories

Resources