1、XML锁定横屏或竖屏
在没有设置屏幕方向的情况下会默认设置为:android:screenOrientation="unspecified"、即未指明屏幕方向、属性取值landscape为固定横屏、portrait为固定纵屏幕、会根据屏幕的方向做改变、在AndroidManifest.xml中配置、如果使某个Activity做横竖屏的变化、在Activity的标签中加入android:screenOrientation="portrait"、效果如下
<pre>
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application ... >
<activity
android:name="com.intozhou.example.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
</pre>
2、JAVA代码实现方式
<pre>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE);// 横屏
//setRequestedOrientation(ActivityInfo .SCREEN_ORIENTATION_PORTRAIT);//竖屏
setContentView(R.layout.main);
}
</pre>