How to give different layouts for different resolutions in android studio? - android-studio

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.

Related

How do I change the size of icons in Android Studio?

I'm building an app with Android Studio, and one of my activities (which lets the user draw on a canvas) has a 'toolbar', with things like 'Clear', 'Undo', 'Redo' etc.
I'm using the built-in icons for this - ie I go to the 'Drawables' folder, right-click, go to 'Add vector asset' and then select the appropriate icon. I've figured out that I can change the size of the icon that gets added, but I can't figure out how to use that.
So, on a phone screen, I'd like to use the standard 24dp icons. However, on a tablet screen, I'd like the icon to be bigger, as they're a bit lost on the bigger screen.
I can't figure out how to do this, though, and I'm not even sure whether I'm using the right approach. I know I can create different drawables sub-folders for different densities, but it's not so much the density that matters as the actual screen size.
What's the best way to go about this?
You should increase the toolbar height, the icon will fit its container automatically.
In case, if you want to change the size of the icon, double-click the xml file of the icon and change the width and height inside. Do not touch the viewportWidth and viewportHeight parameters!
In general, you should not do this, as it wouldn't follow the google guidelines.
app:itemIconsize="30dp"

Creating one layout for different screens in android

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

Do I need to create All folders for layout for all screen sizes?

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.

Different Portrait layouts in android

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

iOS view size and position hard-coded only?

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

Resources