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!
Related
I am struggling for layouts for an Android app. I have defined different layouts for different screen sizes and the current layout directory structure is something like this:
layout
layout-land
layout-small
layout-xlarge
layout-xlarge-land
Problem
The main layout directory files are being displayed for 3.7 to 7.0 which is a very broad range. And text overlap on small screens and if I adjust on small; it becomes very tiny on the large screen.
According to me, the layout small files should be rendered for smaller screens but those files are only rendered for android wear devices.
layout-xlarge seems to work for Nexus 9 to Nexus 10
I want to know, how can I define the different layout for 3.7-5.0 and 5.0-7.0 screen sizes.
The answer is already given by user5594218 but looks like you are still unclear. (maybe you are beginner)
So, here is the step by step guideline
Solution 1: (short and simple)
Navigate to app > src > main > res
Duplicate layout directory by copying and pasting
Rename duplicated Directories e.g layout-sw300dp
Solution 2: (bit lengthy)
Create new resource directory: res > New > Android resource directory
Select Resource Type as layout
Add sw<N>dp in Directory name e.g layout-sw300dp and Hit OK
Navigate to app > src > main > res
Copy layouts XML file inside new directory
//repeat process for other qualifiers
List of Qualifiers to support all screens:
layout-sw300dp
layout-sw330dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
Testing:
This is how it gonna look like, if you did it right.
For more detail and examples, check: Android Application Development All-in-One For Dummies
Create folders like the following
layout-sw300dp
layout-sw330dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
Create also values-folders like
values-sw300dp
values-sw330dp
values-sw480dp
values-sw600dp
values-sw720dp
Navigate app-> res-> layout and right click then New-> layout resource file write the filename correctly and from available qualifiers choose the size you want.
Dear you don't need to declare layout for various screen. just make single layout for every screen and don't fix the width and height of layout. you have to keep height either match parent and wrap content as well as for width.
you should try dp in your layout-height/layout-width/textsize as it is independent of screen sizes.
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...
My first problem is, I am developing Android application where I want to manage the different screen sizes and display the data according to screen size. I have googled for it. Most of the people are saying to create the layout folder for different screen sizes(ex. layout-sw320, layout-sw480 etc..).
So I came up with another thought that I want to create only One layout, and create multiple dimens.xml file(ex. dimens-sw320.xml, dimens-sw480.xml etc..).
I created dimens.xml files like this four different widths(320dp, 480dp, 600dp, 720dp). But When I give dimensions for a textview It's not exactly displaying the ouput according to screen size. Can anyone here explain which dp size used for which screen size. Any help would be grateful.
Thanks in Advance...
Just create a Resource Directory for each category you want.
Project --> app --> res --> Right Click --> Add Resource Directory and select all the qualifiers you need.
For istance place the dimen.xml related to 720dp in values-w720dp directory.
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 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.