Issue
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 [email protected] and xxhdpi would be [email protected].
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.
Solution
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
Answered By - Sanad Liaquat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.