[英]make orientation of an activity both landscape and portrait
我希望我的活動在設備水平時為橫向,在設備垂直時為縱向。 我怎樣才能做到這一點?
在您的活動的AndroidManifest.xml中,當您定義新活動時,必須編寫android:screenOrientation="unspecified"
:
<activity
android:screenOrientation="unspecified"
android:name="com.example.MainActivity"
android:label="@string/app_name" >
或不寫任何內容,因為unspecified
是默認值。
如果必須以編程方式更改方向,則必須編寫以下代碼:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
要么
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
由於該設備具有加速度計,因此您可以輕松地在兩者之間切換
我希望這將有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.