About Android: screenorientation = "Portrait"

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.