Android Landscape Layout - android

I have an activity inside it I have a fragment (Rectangular Box). My landscape layout is not showing even if I had created. My portrait xml file is like this.
First one land and second one is portrait and the down is the Result
but when I turn my emulator to landscape mode it show as in Result in the image.
but when change android:screenOrientation="landscape" in manifest file, it comes perfect as I want but if I use android:configChanges="orientation|screenSize.
It shows the same problem.

Make a folder inside res/layout-land and put the landscape view xml file inside this folder with the same name.This will Solve your problem.

Related

How to set different layouts for different orientations in a fragment

I have an activity which contain 3 fragments. 2 of them have data in a listview therefore when user rotate the screen everything is ok. but on my third fragment which contain buttons, when the user rotate the screen to landscape orientation,everything goes astray!
my third fragment in protrait orientation
my third fragment in landscape!
I have even tried to use scrollview but it's not working because when in landscape i don't want that big space at the middle. i wan't 3 x 2 buttons arrangment(i have 6 buttons.) when in landscape. and i think i can only achieve that by using 2 xml layouts for my fragment.
Question is how can i do that?
Make another layout folder layout-land under res and create landscape orientation layout file under this folder
After great help from sai Phani(see his comments above). i finally achieved my objective which was to create a landscape layout for my fragment by doing the following.
Create a folder under src\main\res and call it layout-land
copy your fragment layout xml (e.g peoplefragment.xml) which is in src\main\res\layout and paste it into src\main\res\layout-land folder. Don't change the file name!
Once you have pasted it, you can change the views alignment the way you would like them t appear on landscape. for my sutuation, i wanted them to appear like this in landscape
You may design your layouts that looks good for both portrait and landscape but you may customize for both orientation.
Look at SO link on the same issue # Android: alternate layout xml for landscape mode. The idea is simply to create folder names the correct way specified in Google documentation.
A good Google webpage is # Supporting Multiple Screens, search for "Using configuration qualifiers". There is a table stating Orientation and the folder names to use.

solving orientation issue in android

I have designed 2 xml files, one portrait and another for landscape for a single activity. I have called one xml file using setContentView(R.layout.portrait); in my onCreateclass. How should I call xml file for landscape.
You should have the same file name for both layout resource files. The only difference is that the landscape layout folder will be called "layout-land" and inside you'll have the layout xml file in landscape mode. When the app is running, Android knows to take the correct xml file and set the layout according to the current mode so you don't have to worry yourself about selecting the proper xml layout file.

how to use Landscape mode in android 4.2

I am using android 4.2 when i am trying to run my program it's working only in portrait mode. Not displaying anything in landscape mode.
I have also used
http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts
http://android.programmerguru.com/android-landscape-layout-example/
but still no success.
Steps i followed
created one more folder with layout-land and keep in same where layout is present.
copied main.xml from layout and pasted in layout-land folder.
added one more button in layout-land -> main.xml.
running in my android device but it's showing only in portrait mode.
please tell where i made mistake ?
Make sure both XML files present in two different folders(namely layout and layout-land) have same name.
try this in your manifest to open activity in Landscape mode
<activity
android:name="com.example.newdatabase.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape">
created one more folder with layout-land and keep in same where layout is present.
copied main.xml from layout and pasted in layout-land folder.
added one more button in layout-land -> main.xml.
running in my android device but it's showing only in portrait mode.
You did it wrong. layout-land should only be used if your landscape layout is different in landscape from what layout is is considered "default" one (which is the one in layout folder). If you do not need different layout, then just keep one file in layout folder and it will be used in either portrait or landscape mode.
You may also want to check your Manifest file and check if you by any chance do not enforce portrait there. ALso "shows nothing" is quite odd - I'd rather bet that your default layout is rendered incorrectly in landscape mode rather than android failed to show anything.

how to adjust the proper interface for both portrait and landscape mode for xml files in android

My problem is that I prepare my xml in portrait mode in Android but when I try to run the application with phone and get the landscape mode, my interface crash. Picture gets smaller and buttons don't appear on the screen. I want my interface to be the same whether the phone is in landscape mode or portrait mode.
How can I solve this problem? Can I prepare two different xml for one class, one for landscape and the other for portrait mode or is there any other solution?
Thanks
You have two options here. The first is to add the android:configChanges attribute to that activity in the manifest:
<activity android:name="the activity's class name" android:configChanges="orientation" >
This will stop android from recreating the activity when the orientation changes. Instead the activity's onConfigurationChanged method will be called.
The other is to make another layout that will be used when the device is in landscape. It would need to be named the same as the portrait layout and put under layout-land.
There's probably other options as well, these are just the ones that I know of.
You can easily have different layouts in different orientations, see "Screen Orientation" in Providing Resources
All you need to do is create a layout-port or layout-land directory under res, and put the alternate XML in there.

how to track the screen in landscape or portrait view in android?

I worked in a tabactivity, I set the gravity for tabs as bottom. If I change the screen from portrait to landscape, I can't see the tabs.
How can I do it? I need an example please.
Thanks.
Assuming you do not have a separate XML file dedicated to landscape format, you might need to create one and specify the landscape-layout look.
Create another main.xml file with the specifics of how your program should look in landscape mode. The file shoud reside inside your res/layout-land/ folder.
When that is all said and done, in potrait orientation, Android will use main.xml found in res/layout and in landscape main.xml found in res/layout-land.

Categories

Resources