I. fixed horizontal and vertical screens
In the Activity configuration of AndroidManifest. xml, add the android: screenOrientation = "landscape" attribute (landscape is horizontal and portrait is vertical ). For example
<activity android:name=".ContactsManagerActivity" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
2. Generally, during screen switching, the activity must be restarted. To avoid restarting, you can set the following attributes in the activity:
Android: configChanges = "orientation", and then re-write the onConfigurationChanged () method in the activity, such
Public void onConfigurationChanged (Configuration newConfig) {// TODO Auto-generated method stub if (newConfig. orientation = Configuration. ORIENTATION_LANDSCAPE) {setContentView (R. layout. imageswitch); // landscape} else {setContentView (R. layout. editcontact); // portrait screen} super. onConfigurationChanged (newConfig );}
In this way, you can achieve horizontal and vertical screen switching without restarting the activity.