(轉)ANDROID強制鎖定豎屏_APP固定設置豎屏或橫屏

1、XML鎖定橫屏或豎屏

在沒有設置屏幕方向的情況下會默認設置爲:android:screenOrientation="unspecified"、即未指明屏幕方向、屬性取值landscape爲固定橫屏、portrait爲固定縱屏幕、會根據屏幕的方向做改變、在AndroidManifest.xml中配置、如果使某個Activity做橫豎屏的變化、在Activity的標籤中加入android:screenOrientation="portrait"、效果如下

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

2、JAVA代碼實現方式

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE);// 橫屏
//setRequestedOrientation(ActivityInfo .SCREEN_ORIENTATION_PORTRAIT);//豎屏
setContentView(R.layout.main);
}



作者:夜澀月
鏈接:https://www.jianshu.com/p/56f5ccd3058c
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯繫作者獲得授權並註明出處。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章