Initially I developed my application for phones only in portrait mode. But now, I want to shift that to tablets as well, but in portrait mode only. My question is, can we define different layouts for portrait mode for different screen sizes. It works on tablets but the UI is stretched. If yes, how..? If someone could give an example.
Yes you can define the same layout for different sized devices.
Assuming you have the layout folder already, you can create another one called 'layout-xlarge'.
In here, create an xml layout with the same name as the one in the layout folder. Now when you run the app, only 10" tablets (devices designated as having extra large screens) will use the 'layout-xlarge' folder.
All other smaller devices will use the 'layout' folder.
Your folder structure will look like so:
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-xlarge/my_layout.xml // layout for extra large screen size
You can do the same for small and large screens, among others.
This is a rather brief description and you would do well to read this when you get a chance:
http://developer.android.com/guide/practices/screens_support.html
i think you have to create 3 layout in your resource folder and each one has same name xml file
that are
layout (contaning a.xml, b.xml, c.xml)
layout-large (also contaning a.xml, b.xml, c.xml)
layout-small (also contaning a.xml, b.xml, c.xml)
check your application on different size of emulators like QVGA, HVGA, etc.
Yes you can develop define different layouts for portrait mode for different screen sizes
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large screen size for land scale
by default res/layout/my_layout.xml this means you are going to create my_layout for portrait mode.
just take care of folder hierarchy .
for more details
Related
I used a layout for different resolutions but it did not look good. So I want to know how to make different layouts for different resolutions.
Mr Aks, you are supposed to create different folders for each resolution, in the resources' folder. The location will be something like this, C:\Users\Username\AndroidStudioProjects\Appname\app\src\main\res. The folder names you can keep will be:
layout (layout for normal screen size)
layout-small (layout for small screen size)
layout-large (layout for large screen size)
layout-xlarge (layout for extra large screen size).
If you need more help than you can write more questions, I will answer them.
I have created a layout that has xml files, these xml files are joined by "include" to make one layout in hdpi.I have texts in these files. I have given size for the text in dp. However, when i run the app in smartphone with mdpi screens, my layout heigh can not fit the screens. My layout's not resizing. Please help me with this question
I am creating an app targeting all screen sizes and densities.
Do I need To put my layout in all folders named-
layout-large-port
layout-large-land
layout-small-port
layout-small-land
layout-normal-port
layout-normal-land
layout-xlarge-port
layout-xlarge-land
or there is any other standard way?
Also, what about the text size in each layout? If I need large font in xlarge size an small font in small size, then how to adjust same?
Android tries to find the most specific match when looking for a resource. If none is found, it will try less and less specific until a match is found. So for example, if you're running on xlarge-land, then it will look for any resource first in layout-xlarge-land, then in layout-xlarge or layout-land (not sure which order) and finally in the unqualified layout. This means if you design your layout XML's in such a way that they're generic, you don't have to provide every possible bucket.
The Supporting Different Screen Sizes section of the Android Developer Training goes into this in detail. It also includes a useful "layout alias" trick that you can use to avoid copy-paste coding.
I was created simple currecnyConverter apps in android But I got Problem is that when i did run this apps Nexus S(4.0",480 * 800:hdpi) emulator in Protrait is working fine but same apps run on landscape mode my button and component not fit on the screen so I want run my apps on any mode and any android version.please
can anybody give me answer.
Thanking you
You have to go through the below page:
http://developer.android.com/guide/practices/screens_support.html
You have to design the layout for landscape mode in layout-land folder with same name as in your Portrait mode.
For more info see the above page.
Thanks.
You need to create different layout for landscape and portrait.
Follow this
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
I'm new to Macs and iOS, I got my app running on webOS, Android, and WPF/Windows. In all cases the size of, say, a 'widget' to display a bunch of text, can change depending on the dimension of the text to be displayed, as well as the position can be up against another widget. As the text size changes, the position will change so that all the widgets are crammed together nicely.
I've been searching for this capability in IOS4 in books and on-line, and it's starting to look like in iOS, you have to actually calculate the size of the text to be displayed in ViewText and then change the dimensions of ViewText, which of course then bumps other Views around to accommodate this size change. It sounds like a nightmare. Isn't there some other way to do this (like all the other GUIs can do) to size based on content, and to position relative to other Views like stacking them all together whatever size they are?
Same with ScrollView, it looks like the size of the window you actually see has to be manually specified as well, instead of, say, taking up the entire viewable window and then you can populate the ScrollView with a bunch of sub-views, some of which are below the initially viewable area? I tried this in Xcode4, but so far, haven't gotten it to work.
Similarly with creating an object with a NIB and instantiating that NIB onto an existing View, how does it determine where to position this NIB onto the existing screen?
Thanks!
Paul,
For the scrollview you need to set the bounds so it fills the screen or the area you wish it to occupy, it will then automatically generate scrollbars based on the layout within it. In the land of iOS you do have to do extensive layout work such as positioning and sizing your controls but you can also use the UIAutoResize (if I remember correctly) masks such as if they are anchored to a size, fill the area, etc. It's a little complicated to learn initially but you'll get the hang of it.
As for text you just need to use the right control, I believe what you want is a UITextView and set the options on it as needed.
When you view a XIB it's going to layout initially as you have it, again, you need to position your controls AND set their anchors (autoresize masks) so they adjust based on the screen size (phone vs. pad) and orientation: landscape vs. portrait.
HTH