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...
Related
I have a problem with Android Studio when I have to adapt my application to different screen sizes. I tried creating diferent layouts depending on the screen size (small, normal, large, xlarge), but it doesn't work and I don't know why. No matter what the screen size of the mobile is, it uses the normal screen size layout. Here I leave you 2 screenshots: The first one is the res folder in the explorer, and the second one the folders in android studio.
Res folder
Android Studio folder
Try this approach:
//create a folder structure like this
/layout
/layout-sw300dp
/layout-sw400dp
/layout-sw600dp
/layout-sw800dp
Now you can place the respective layout files in the corresponding folders!
I hope this helps! Good luck!
I have an application where I use background images.
I don´t want my images to be stretched or deformed when I run my application on different screens with different ratios.
I already have different images for different screen sizes.
Can someone please explain to me how Android Studio handles the image sizes.
How can I make it that the image isn´t streched, but a sector that fits the screen is being displayed?
Android System uses resource qualifiers/filters to load different resources based on current screen configuration.
Now you have different images for different screen sizes, Good!!
the Folder structure would be something like this.
res
-drawable-mdpi
-drawable-hdpi
-drawable-xhdpi
-drawable-xxhdpi
Now when you run your Application on a device with mdpi screen, android loads images which are under drawable-mdpi folder, and when you run your application on a device with screen density of xhdpi android loads images from drawable-xhdpi folder.
Instead of setting the image as a background for my layout I created an image view. There I set the scale Type to centerCrop and it had the wanted effect!
In my Eclipse project I currently have the following folders:
layout-land
layout-large-land
layout-sw600dp-land
layout-xhdpi-land
(I have others too, but the problem right now is for landscape layouts only.)
My layout is quite specific: it varies greatly when I change the size of the screen in Graphical Layout in Eclipse.
From what I have learned from Android docs and from AVD setup, normal screens are from 3.6" to 4.9". Large are from 5.0" to 7.4". Small are up to 3.5".
I go to my xml layout file in the layout-land folder. The screen size chosen already is 4.0", which is all good, because we're in the landscape layout folder for normal screen sizes. I now choose a screen size of 5.1". The editor opens the xml file in the layout-large-land folder -- also OK.
I now choose this screen: 4.65" (720x1280 xhdpi). The size of 4.65" is still in the normal range, and the editor uses the xml file in the layout-land folder. This should be ok, except the fact that my layout changes greatly! I thought that maybe this is because of xhdpi, and that's why I created the folder above (number 4), but that does not seem to work with Eclipse (the xml file is not used for this screen). Same problem occurs with 4.7".
So what my question really is:
How can I provide different xml layouts for screens in the normal range?
Note that there Android platform doesnt consider the screen sizes as much as the dp or Density Pixels. Also there are several of known issues with Eclipse and ADB Plugin for eclipse. The best way to test is with the actual device. For the information to support the screens, we just have to place the files in folders below and it will possibly work for most of the devices with the specified DP.
layout-land
layout-large-land
layout-sw600dp-land
layout-xhdpi-land
http://developer.android.com/guide/practices/screens_support.html
I've a large image logo I'm currently scaling (usually down) to fill 50% of screen. At first I placed it in the base /res/drawable folder. It worked fine for most devices, but on some low-end phones with small screens the scaling introduced aliasing and it looks horrible. So I distributed the images as follows:
/res/drawable
-Large image, intended to be used on most devices
/res/drawable-normal
-Smaller image, intended to target smaller screens
However, when testing on Samsung Galaxy Tab 2 10' it picks the image in normal folder instead of the image in the base drawable folder. I know this tablet fits in the drawable-xlarge category since it is picking other resources from there. So I had to come up with this directory structure for the thing to work:
/res/drawable
-Large image, intended to be used on most devices
/res/drawable-normal
-Smaller image, intended to target smaller screens
/res/drawable-xlarge
-Same image as the drawable base folder, only used for the tablet to select the correct image.
Now it works as I want, but I can't understand why the system selects the normal folder for an xlarge device. Shouldn't it look first in the xlarge folder and then fallback on the base drawable folder?
Thanks in advance.
It falls back in a scaleable manner.
If it can't find Xlarge, then large is a closer match then normal is a closer match then the default folder
Reference:
How Android finds best matching resources
Android.Developer
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.