通常我們的應用只會設計成橫屏或者豎屏,鎖定橫屏或豎屏的方法是在manifest.xml文件中設定屬性android:screenOrientation為"landscape"(橫屏)或"portrait"(豎屏):
<activity
android:name="com.example.kata1.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
其實screenOrientation還可以設置成很多值:
android:screenOrientation = ["unspecified" | "behind" |"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"userLandscape" | "userPortrait" |
"sensor" | "fullSensor" | "nosensor" |
"user" | "fullUser" | "locked"]
參考處:http://blog.csdn.net/oracleot/article/details/19045011