<
activity
android:name
=
".Activity"
android:label
=
"@string/app_name"
android:screenOrientation
=
"landscape"
>
<!--screenOrientation為固定畫面的方向-->
<!--參數為 landscape為橫向 portrait為直向 nosensor為關閉重力感應器-->
</
activity
>
但若想要固定螢幕方向的類別不是
extends Activity, 就要將設定寫在.java裡了, 比如:
DialogFragment extends DialogFragment{
Activity activity;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
// 在此頁面一開啟一定會被執行到的地方, 設定此頁面為直向
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
@Override
public void onStop() {
super.onStop();
public void onStop() {
super.onStop();
// 離開此頁面時, 旋轉功能要恢復正常
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
沒有留言:
張貼留言