1
votes

I have implemented an application for android 7 incs tablet.In my application i have used two types of layouts in layout-land and layout-port directories with same xml name and different designing.

In this application the tablet view is in landscape mode as by default when i change the orientation of emulator the the view is calling portrait xml from layout-port and if again change emulator orientation it is not getting xml view from layout-land.

I have implemented my application as follows:

    if(wm.getDefaultDisplay().getOrientation()==1){
       //portrait view code
        }  

       else{
             //landscape view code
              }

from the above logic i can get the view from land scape to portrait but i can't get same view portrait to landscape.

How can i get my land scape view when i change landscape to portrait to landscape?

please any body help me?

2
maybe some error when you are inflating layouts? Usually you won't need the getOrientation() function if you properly implement fragments. please post more code!ramdroid

2 Answers

2
votes

That seems to be a problem with the emulator. You don't have to implement from code the orientation changes, since the system have by default this behavior. Just place your xml files in layout-land and layout-port and on a real device it will work fine.

The bug has been reported and you can see this here

1
votes

You can use this code:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

or

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

You maybe also have to set this in your manifest under activity:

android:configChanges = "orientation"