关于android:screenOrientation="portrait"

当在AndroidManifest.xml文件中定义了android:screenOrientation="portrait",就表示当我们切换横竖屏的时候,屏幕的内容始终以竖屏显示,而不会根据屏幕的方向来显示内容

AndroidManifest.xml文件

 

<?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文件

<?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
="横竖屏切换测试"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height
="wrap_content"
android:id
="@+id/et"
/>
</LinearLayout>

TestActivity.java文件

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(
"我是onCreate方法");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
tv.setText(
"横屏");
}
else{
tv.setText(
"竖屏");
}

}
}
可以亲测一下,以验证我刚才说的结论
posted @ 2011-05-24 10:27  And.He  阅读(26535)  评论(1编辑  收藏  举报