简体   繁体   中英

Android Screen orientation landscape error?

I'm new to android and making an app in which there is layout design for both portrait and landscape mode. The app is running fine in both screen orientation except for one activity. The activity is working fine in portrait mode when i go from one activity to another, but crashes in landscape mode. I tried to solve this in different ways through Google search but didn't succeed. Please someone help me. Thanks

希望在AndroidManifest.xml的活动代码中使用此android:configChanges="orientation" ,希望这会有所帮助

Make two different resource folders in res folder like below:

1) layout --> put your main.xml

2) layout-land --> put your same main.xml in here too.

Note: in both res folders the name of layouts must be same.

Edit: well android handles orientation change automatically after above mentioned

procedure.. but if you want to handle it manually then here is the code to handle..

public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);

if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
{
  Do something in Portrait
} 
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
  Do something in Landscape
}
}

Add this below line in your manifest to the activity you want to handle orientation:

android:configChanges="orientation|screenSize|keyboardHidden"

Use this in Manifest.

<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:name="VncCanvasActivity">

This line specifies the screenOrientation as landscape, but author goes further in overriding any screen orientation changes with configChanges="orientation|keyboardHidden"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM