how to use Landscape mode in android 4.2 - android

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.

Related

Android Landscape Layout

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.

Viewing the Graphical Layout Landscape Android

I have been trying to develop an application in a landscape mode so I placed "android: screenOrientation="landscape" in my Manifest. It worked well, however, the graphical layout of my xml files are still not in landscape mode so I cannot design my UI well. Any help? Thanks
Follow below screenshot
you should design separate UI for landscape mode and put in layout-land folder. check this link
go to res folder in your project, and create a new folder in it name it as layout-land

How Do I Handle Layout Changes When Orientation Changes?

I am trying to simply alter the setlayout when I rotate my device so that I can have a layout of Views for a particular activity that is suited to the current orientation of the Android device but I am confused about the best way to achieve this.
I have referred to the following android doc:
Handling Runtime Changes
I do not need to save any data from my Activity so don't think I really need to use the onRetainNonConfigurationInstance() method. I tried handling the orientation change myself through the onConfigurationChanged() method, where I find the current orientation then set the layout as required but this results in views that no longer work. Is there something else I need to do in onConfigurationchanged()?
Thanks
To get a different view for landscape as opposed to portrait, you would place your layout XML file in both of the following resource folders:
/res/layout - Portrait
/res/layout-land - Landscape
This is, of course, if you have the same views within both, otherwise you may get some NullPointerExceptions.
You can create a new directory under res called "res\layout-land", create an .xml layout file in both "res\layout" and "res\layout-land" that have the same name. For example: "myLayout.xml". Android will automatically use the layout from the -land directory when in landsacpe orientation and the other when in portrait.
in your projects res folder you should have a layout folder. Create a new folder in the res and call it layout-land. Now create your second set of layout.xml files that are specific to landscape oriented devices. Save them in this layout-land folder. The system will handle the rest for you.
check out this page and scroll down to "Providing Alernative Resources" for more detail about different qualifiers you can use on your res folders.
Edit: What device are you using? I created a quick test project that is nothing but hello world but displays different text from a layout stored in res/layout-land folder.
I tried it once with and once without configChanges="orientation" in the manifest. When I run the app and switch orientations the layouts behave as expected. The layout from layout-land is displayed when device is landscape and layout from plain layout folder is shown when device is in portrait.
The device I tested on is Sidekick 4g. Download the test project and report back how it works on your device if you like.

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