2

I am developing a app it has two activity. A1 only supported portrait, A2 supported two orientation. When the device is portrait and then I switch to A2. The layout of A2 is fine. But the device is landscape and then switch to A2, the layout confused. The first width and height are exchanged.

I setup the UI like this:

onCreate () {
  DisplayMetrics dm = new DisplayMetrics(); 
  getWindowManager().getDefaultDisplay().getMetrics(dm);

  setupUI(dm.widthPixels, dm.heightPixels);
}   

Have anyway to set the default orientation or other way can resolve this problem? Thx.

monkid
  • 69
  • 2
  • 2
  • 7

2 Answers2

6

add this tag to your activity in Manifest

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:screenOrientation="portrait"
Omar Farhat
  • 668
  • 4
  • 15
4

You can force an activity orientation in manifest like this:

<activity 
    android:name=".A1" 
    android:label="@string/app_name" 
    android:screenOrientation="portrait">
</activity>

This way, Activity A1 will always be in portrait orientation, even if you switch back to it from Activity A2

hendrix
  • 3,364
  • 8
  • 31
  • 46