Portrait, Landscape in Android app - android

I am designing with LinearLayout which is working for portrait but landscape it does arranged properly. I do not use x,y positions. If I change anything in xml it affects the design -- how do I design both portrait and landscape?

You can specify a layout-land folder, to put all your landscape layouts (duplicate them, but with little differences in order to they show properly in corresponding orientation). In order to avoid this, you should work with RelativeLayouts. But if it's too late and you don't want to change everything, you can create the mentioned folder and make the proper layout changes.
So you will have a
layout/activity.xml
and a
layout-land/activity.xml
If your app is big, it might become a pain to make every change two times, but it's not so bad.
Not recommended, but you can also avoid changing orientation by supporting only portrait orientation in your app: you would have to put "android:screenOrientation="portrait"" in your app's Manifest then.

You can define a second xml file that is the layout for the landscape version. That file must be named the same and placed in a layout-land folder:
i.e.
Portrait:
layout/main.xml
Landscape:
layout-land/main.xml

Related

How to use tablet-specific layout when in landscape mode?

I have defined a tablet-specific layout in the res/layout-sw600dp folder. Now. It loads correctly in tablet emulator and is checked and managed by code as expected. The problem is that I cannot access this layout variant to use in mobile emulator after I check that orientation is landscape. When I type in code R.layout., no hint is given as to the specific tablet layout, only one instance is given, activity_main. How can I use that tablet layout in the landscape orientation as well?
./app/src/main/res/layout-sw600dp/activity_filter.xml
./app/src/main/res/layout/activity_filter.xml
The "smallest width" qualifier doesn't care about device orientation. You'll have to make a copy of your layout and put it in the res/layout-land/ directory if you want that same layout on phones in landscape.
If you don't want to have two exact duplicate layouts (one in sw600dp and one in land), you can look into using a resource alias: https://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters

Layout landscape mode and Categories of layout folders

I created following layout folders.
res/layout-sw320dp
res/layout-sw480dp
res/layout-sw600dp
res/layout-sw720dp
It is ok, layout from corresponding smallest width in dp folder are triggered.
Is it sufficient to create these four folders and our app will looks fine on any density screen or any size screen ? Plz explain this in some detail.
To create layout for landscape mode. what can i do with this ?
what is the use of multi port ui using fragments ? Is it used for landscape and port-rate layout in one xml file ?
By default, the layouts in /res/layout are applied to both portrait and landscape device screeens.
For example you have main.xml
/res/layout/main.xml
you just need to add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments, and so on for all of your layout files.
You just need to have same files for land and portrait but with different folders and of course with different modifications.
Hope this to help!

Is the default layout folder necessary when having layout-port and layout-land?

My app uses a specific layout depending on the screen orientation layout-port and layout-land and I don't currently use layout. Reading the documentation the developers mentioned that we shouldn't make assumptions about the default orientation because some devices might have a default orientation of landscape.
Is it safe then to not include a layout folder and only have layout-land and layout-port ?
Build scripts may need it to be present but you can always keep layout folder empty anyway, however this is not the best approach imho. I'd consider layout the default layout - but it is up to you if you put portrait or landscape layouts there (I'd suggest putting portrait) so in that case you need just layout and layout-land.

How to handle size and position of controls in Android's Activity for portrait and landscape orientation?

I want to desing a GUI for android's tablet. By default i want to use landscape orientation of this application, so i placed the controls (text boxes, text views etc) accordingly, but when i change the orientation of tablet from landscape to portrait, whole GUI of activity gets distrubed. Can anybody guide/help me what is the best approach for designing of GUI in android such that controls appearance should remain correct in either orientation (portrait or landscape)? Thanks in advance.
You have to create another folder in the res directory called "layout-land". Put the layout file for landscape in this folder and the one for protrait mode in the normal "layout" folder. Both files must have the same name. Android will automatically chose the correct layout depending of the current orientation of the device.
Check the link below, it will provide all information about how to design an application to support multiple screens with different sizes and resolutions.
Supporting multiple screens

Change elements orientation from portrait to landscape mode

i want to have two buttons with vertical orientation when the device is in portrait mode,and in horizontal orientation when it is in landscape.How will i get it with only an .xml file?May i use something like "styles.xml" and say that if i have portrait do this and if i have landscape do the other one?Thanks
The layouts in /res/layout are applied to both portrait and landscape.
To use a different layout in landscape, create a folder /res/layout-land and create another xml file here with the same name. Android will automatically choose the layout corresponding to the current screen orientation.
EDIT :
If you cannot create a second folder or are concerned about performances, then you can override the onConfigurationChanged() method, as explained here.

Categories

Resources