When Android: screenorientation = "portrait" is defined in the androidmanifest. xml fileWhen we switch between the portrait and landscape screens, the content of the screen is always displayed on the landscape instead of in the screen direction.
Androidmanifest. xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
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>
</application>
</manifest>
Main. xml file
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/TV"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "horizontal and vertical screen switching test"
/>
<Edittext
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Id = "@ + ID/ET"
/>
</Linearlayout>
Testactivity. Java File
Package com. test;
Import Android. App. activity;
Import Android. content. res. configuration;
Import Android. OS. Bundle;
Import Android. widget. edittext;
Import Android. widget. textview;
Public class testactivity extends activity {
Edittext et;
Textview TV;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
ET = (edittext) findviewbyid (R. Id. Et );
TV = (textview) findviewbyid (R. Id. TV );
System. Out. println ("I am the oncreate method ");
}
@ Override
Public void onconfigurationchanged (configuration newconfig ){
Super. onconfigurationchanged (newconfig );
If (newconfig. Orientation = configuration. orientation_landscape ){
TV. settext ("Landscape ");
} Else {
TV. settext ("portrait ");
}
}
}
You can test it to verify the conclusion I just mentioned.