Android : Understanding drawable folder
By default Android maintain three folders for the images with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
hdpi image folder maintain images for the Android Broad Screen set or Android Phones with the Higher resolution.
ldpi for Lower images quality which supports by the earlier sets of the android
mdpi for medium images support
xhdi images folder for devices with maximum resolution.
Android OS select the image it self by checking the compatible device and its resolution.
Hope it helps. Accept if you get your explanation.
Android Studio drawable folders
If you don't see a drawable folder for the DPI that you need, you can create it yourself. There's nothing magical about it; it's just a folder which needs to have the correct name.
Clarifications about android drawable folders
Let's say I have res/drawable-mdpi/image.png. Does that mean the image is scaled if I have a screen different from mdpi
Yes.
or will it also be scaled on mdpi screens resulting in possibly heavier image size on every device?
No.
if I provide a version of this image for every screen density, the scale will never happen?
Yes. Your APK will be larger, due to the 7 copies of the drawable.
How to deal with icons for which I do not have multiple versions?
Option #1: Decide what density that particular version belongs in, and put it there. Android will upsample or downsample the image for devices operating at other densities.
Option #2: Put it in -anydpi
or -nodpi
, in which case Android will not upsample or downsample it. However, in this case, you need to be controlling the size of the image yourself (e.g., in the ImageView
).
Option #3: Replace the icon with one that either you have all relevant densities or one that is an SVG that works as a vector drawable when imported using the Vector Asset Wizard in Android Studio.
The decision-making needs to be based both on memory consumption and what the result looks like. A low-memory solution that looks awful is unlikely to be a good choice.
should I just move everything under nodpi
Probably not.
or some high resolution like xxxhdpi where it can only be downscaled?
Probably not. It is unlikely that a massively downscaled version of your icon will look very good.
What's differences between 'drawable' folder and 'drawable-hdpi-ldpi-mdpi-xhdpi' folders?
res/drawable/
is equivalent to res/drawable-mdpi/
. The suffix-less name is there for backwards compatibility, before the densities were added in Android 1.5 or thereabouts.
is enough to create suitable image size rate for all devices?
If you do not mind Android scaling your images up and down for other densities, yes. Usually, the quality will degrade the further the density is from the starting point (in this case, -mdpi
.
Should I create image size rate for each folder(hdpi, mdpi, ldpi, xhdpi) ?
That depends on the image and the results of the automatic scaling. Many developers will ship a couple of densities, but not all of them, and tending to aim towards higher densities (e.g., -xhdpi
). But, you are welcome to do what you want, so long as you feel that your users will be comfortable with the image quality that you deliver to them.
How to create drawable folder in res?
Yes it already exist.
you have to change the project structure
Click on top left dropdown where Android Appears.
Select project from this dropdown and you will be able to see all drawbale folders.
Is there any need to use different drawable folder version?
Yes, it's okay to just put all your drawable items in the drawable folder.
You may use these versioned folders (e.g. drawable-v24) to store different drawable items for different API Versions. yet you must have a drawable item with the same name in the simple drawable folder, therefore you won't receive a "Resources Not found" error while your app is running on a device with a lower API level.
Related Topics
Android Draw Route on a Mapview with Twoo Poi-S
Android - Ondatechangedlistener - How to Set This
How to Stop/Cancel Android Countdowntimer
How to Implement a Gcm Hello World for Android Using Android Studio
Handling Keepsynced() While on Background on Android and with Fcm
Android Java.Util.Concurrent.Timeunit Convert Milliseconds to Minutes
Get List of Active Pendingintents in Alarmmanager
Connectivity_Action Intent Received Twice When Wifi Connected
Advantages of Using Bundle Instead of Direct Intent Putextra() in Android
Android Audiorecord Supported Sampling Rates
Android - Way to Appear Bordered Text on the Textview
Android Raw Folders - Creation and Reference
How to Restrict Content Provider Data Across Applications
Extracting Information from a Scanned Gs1-Type Barcode
How to Calculate Phone's Movement in the Vertical Direction from Rest
How to Handle One-Shot Operations in Jetpack Compose