Images not picking up from different density folder in Android studio - android

I have kept different density images in 4 different folder. Example. In mipmap-hdpi, mdpi, xdpi, xxdpi, xxxdpi. And I'm using xiomi mi4i phone to test. By checking the density of phone I found out it's xxdpi.
I used ImagView to set image. Like
android:src="#mipmap/icon"
But what I'm finding out is it is taking from mdpi folder. I cleaned rebuilt project also. Nothing is working out. Can somebody please help what could be the problem.
For my verification what I did was I created new test project with only Imageview and kept four different size icons corresponding density folder. But still the image is picked from lower density folder.

You should use this line in xml :-
android:src="#drawable/icon"

Related

Android: Same Image needs to be added in all drawable folders?

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.

supporting different screen sizes in android studio

I have developed an app in Android Studio having 12 different images and I need to support my developed app in multiple screen size, so I have created different layouts such as small, normal, large and extra large even drawable folders too of different dpi, while executing my app works pretty good in tablet but it's not working for small screen size:
res/new/layout-small
res/new/layout-normal
res/new/layout-large
res/new/layout-extra large
drawable
res/new/drawable/mdpi
res/new/drawable/ldpi
res/new/drawable/xhdpi
res/new/drawable/hdpi
and I have created main.xml layout
The default path for ressources in a android project are res/drawable-mdpi res/drawable-ldpi res/drawable-xhdpi res/drawable-hdpi etc, you should try that instead.
Hope this helps.
Please also add the default layout folder. May be it's not picking the resources from required folder...

Default drawable folder in 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

Android image drawable folder issue

in my android application I've the same image in both the drawable folder and drawable-hdpi with different names (svs.jpg and svs1.jpg)
First, I've used svs.jpg (drawable folder)
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/svs"
/>
In one system it runs without any hindrance, but it shows error in another system (Inflate exception error in binary xml file). So I've used the image svs1.jpg as android:background="#drawable/svs1". Now it is working..
If I use svs1.jpg on the first system it shows error. I don't understand this problem. Can someone say why is this happening?
Images in different resource folders are meant to get the same name so the device will choose the one to use.
If they don't, I suppose some device are looking for the image name in the 'drawable' and crash if they don't find it, other device will look in the 'device-hdpi' folder and crash if they don't find it.
more information on supporting multiple screen here.
It seems you are really misunderstanding what these folders do.
Your android will select folder based on it's screen size or pixel-density of device on which u run it
If Your device has a medium Pixel density and a large screen. So it selects its resources from the res folders with those given qualifiers.
res/layout-large/my_layout.xml
and images from
res/drawable-mdpi/my_icon.png
You cannot tell your device to get images from the hdpi folder because it does not have a high pixel density.
So u give name of image same in all drawable folders .. Your device by default ll decide from which folder to take image , you need not worry about tat.
and just make sure the right images are in the right folders.

Where to insert images in eclipse for android

I am new to Android and I need to use images in my XML file.
A tutorial says that I have to place them in drawable directory, but I can't find it as I find drawable-hdpi, etc.
drawable folder is divided into into three part according to device screen size h- high, M- Medium, L- Low because in android different size of device available in the market and android device screen divide into three type h,m,l based on density specific according to device size android pick the image from specific drawable folder h ,m ,l if you dont want to density specification in your application then add new folder with the name of drawable.
I hope it is more use full to you.
You can create the drawable folder yourself by right-clicking "res" -> "New" -> "Folder" and naming it drawable.If you do not need your images to be density-specific, you can put your images there.
you can create your own drawable folder in res directory. But remember keep the images in that folder which are common for all screen size devices. drwable-hdpi means this directory contained the images will be loaded when the device has higher dpi. similarly drawable-mdpi and drawable-ldpi are there.
Those which you found are drawable folders.. Insert the images in all three of them. So that at time of change in definition of screen images can be changed accordingly. For now, Insert same image in all three of them.
You can create your own drawable folder. But its good to use these at first then when you run your application on device you will come to know the difference.
drawable-hdpi drawable-mdpi etc are the different type of drawables . you can keep your images in these folder (any one at the initial level).
But they have some diffrence according to the resolution of the screen & density of android device. Further you can check the diffrence between them and keep the images as per need.
see this for more details: Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi
and Supporting Multiple Screens
you can create a drawable folder in the /res folder of your project and put your images there.
drawable-hdpi(mdpi/ldpi) are used separate different resources for different type of screen. take a look here to know more about multiple screen handling
I realize that this question is rather dated, but...it came up when I Googled the issue of inserting images into an Eclipse Android project, so....
Actually, those folders are mipmaps and they are used by the graphics subsystem to provide seamless zooming, as well. I would suggest creating proper mipmaps using an editor, as opposed to providing only one resolution choice.

Categories

Resources