android-screenOrientation 橫豎屏設定

來源:互聯網
上載者:User

標籤:

1.xml中設定,這個主要是在AndroidManifest.xml 中尋找activity,然後在裡面設定屬性,如下

<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher_calculator">        <activity android:name="Calculator"                   android:theme="@style/Calculator.Theme"                  android:windowSoftInputMode="stateAlwaysHidden"                 <!--螢幕設定--> 
          android:screenOrientation="portrait" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.APP_CALCULATOR" /> </intent-filter> </activity> </application>

這個屬性android:screenOrientation="portrait"有以下幾個屬性

"unspecified":預設值 由系統來判斷顯示方向.判定的策略是和裝置相關的,所以不同的裝置會有不同的顯示方向.
"landscape":橫屏顯示(寬比高要長)
"portrait":豎屏顯示(高比寬要長)
"user":使用者當前首選的方向
"behind":和該Activity下面的那個Activity的方向一致(在Activity堆棧中的)
"sensor":有物理的感應器來決定。如果使用者旋轉裝置這螢幕會橫豎屏切換。
"nosensor":忽略物理感應器,這樣就不會隨著使用者旋轉裝置而更改了("unspecified"設定除外)。

2.代碼中進行設定

//設定橫屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//設定豎屏setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);/*因為橫屏有兩個方向的橫法,而這個設定橫屏的語句,如果不是預設的橫屏方向,會把已經橫屏的旋轉螢幕180°。所以可以先判斷是否已經為橫屏了,如果不是再旋轉,不會讓使用者覺得轉的莫名其妙啦!代碼如下:*/if(this.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT){setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}

 

android-screenOrientation 橫豎屏設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.