I found this link Why don't some xhdpi mobiles display image located in /res/drawable only? and according to the answer "you should not put images files in the drawable folder". Is it true? there is a link in that answer but does anyone have an official reference on this matter. I search for an answer but still did't find any. Please help me to understand the drawable folder.
"you should not put images files in the drawable folder". Is it true?
It is not true, as long as you remember the fact the drawable is a shortcut for drawable-mdpi, so your drawable as in fact been scaled density-wise.
Drawable folder is meant to hold images.
There are many drawable folder with customization, like
drawable-mdpi : devices which fall under medium density will take images from this folder.
drawable-mdpi-port : devices which fall under medium density and the orientation is portrait will take images from this folder.
Priority matters. Suppose the device is medium density and not in portrait mode, then it will take in drawable-mdpi.
The default folder is drawable, this folder will be in use under the following situations.
If the device doesn't fall under the specified customization.
If the item image is common for all density and resolutions.
Related
What size of image should I put into drawable folder which is not drawable - ldpi, hpi, mdpi, xhdpi,xxhdpi, xxxhdpi? Or do I still need the drawable folder?
Yes, we still need drawable folder. All the folders you mentioned help android app to store different density images according to their density but when you access them into your app system will select the appropriate image based on the screen's API.
You could also follow documentation for further details here.
I am directly adding images in drawable folders and it is coming fine with ImageView tag android:src="#drawable/image_name" but I wonder what to do with the other drawable folders as shown below.
Do I need to add same image in all drawable folders or my way of adding images in drawable folders is wrong?
Please help me!
The image is same, but the size should be different for each folders.
If you add the image only in drawable folder, same image will be loaded for all screen resolutions. So for eg: if the image size is small, this may result in bad image quality.
You can find a similar question here
I use Android studio plugin Android Drawable Importer
All these drawable folders represent different android phone densities. The best folder to put your images is drawable-xxhdpi as android automatically downscale or upscale the images depending on your devices density and most phones these days are on xxhdpi density.
If you put a image in drawable folder only there are chances that image may get distorted(as it upscales) in xxxhdpi density.
If you are putting images in xxhdpi ,make sure you create your images acc. to xxhdpi resolution.
If you don't feel the image is looking right in some phones than check the density of that phone and put an image in that specific density folder acc. to it's size(reduced or increased).
Just put it in the drawable folder, no need to put it in other drawable-... folders because those folders and contents inside are created automatically by android studio.
I am very curious what kind of size of images I have to hold in Resources -> drawable folder.
Because in other drawable folders like mdpi, hdpi and etc I am holding size of images regarding documentation. As I know in drawable folder there should be default images if device do not recognize what kind of type of drawable folder is required, then application loads from default folder - drawable. So what kind of size images, you would suggest to put? Thank you for all answers and suggestions.
Well, I find out that is mostly recommended to have images in drawable folder(default) from drawable-hdpi folder.
And here is recommended sizes for each folder: http://iconhandbook.co.uk/reference/chart/android/
Ok so I have 4 folders in my res directory: drawable-mdpi,drawable-hdpi,drawable-xhdpi,drawable-xxhdpi. I wanted to know how to make a DEFAULT drawable folder where I could place images and if there was no image found in the specific density folders, the android device would look in the defualt one. So I created one with no qualifiers named drawable. The problem is when I put an image in my new created folder, it appeared differently than when I placed it in a specific density drawable folder.. Even though I was using the exact same image. How did changing folders affect my image..?
The default drawable folder will be interpreted as mdpi, essentially. So any image you put in there will be rendered 1:1 on an mdpi device, scaled to 1.5x on hdpi, and scaled to 2x on xhdpi, etc.
All those folders are related to the phone you are using, you can open a default drawable folder named "drawable" but if you want to know, the drawable-mdpi for example is for samsung galaxy tab 10" (and more), you can read more here: http://developer.android.com/guide/practices/screens_support.html
I have two drawable folders: drawable-mdpi and drawable-ldpi
I want to keep this structure (i.e. I don't' want to move my images to /assets), so that Android will automatically pick the appropriate artwork depending on the device density, however, on occasion I need to access the larger drawable version on the smaller device.
Is there a way to access the drawable-ldpi folder from code? I thought the following might be the answer, but it did not work:
Uri path = Uri.parse("android.resource://com.example.test/res/drawable-ldpi/icon");
imageview.setImageURI(path); //assume imageview is already initialized etc.
I get a java.io.FileNotFoundException (no such file or directory) warning (it doesn't crash, but it just doesn't load either).
Thanks so much for your help!
probably not much help but there is Resources.getDrawableForDensity() but this is for API 15 :-(
Generally, if you ever need to use the HDPI version, keep ONLY the HDPI version of the image, and the lower density phone will automatically use the HDPI drawable because it has no choice (i.e. a lower resolution image with that drawable name does not exist).
If you really need to switch between the hdpi and mdpi version I would suggest using a different filename and swapping programmatically, or showing/hiding XML elements if you prefer doing it that way... but that seems a little heavy-handed.
ImageView image = (ImageView)findViewById(R.id.imageView);
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.abc);
image.setImageBitmap(bm);
Try reading THIS LINK also for more study over hdpi and mdpi concept