Android横画面縦画面設定


Android横画面縦画面設定
ブログの分類:
Android
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//フルスクリーンモード設定強制的に横画面setRequestedOrientation(Activity Info.SCREEN_ORIENTATION_PORTRAIT);//縦画面で私が作ったものの中にはタイトルバーを取り除くのも使いました.私もrequestWindowFeature(Window.FEATURE_NO_TITLE);
 
 
垂直方向中央:
android:layout_centerVertical="true"
 
水平方向中央:
android:layout_centerHorizontal="true"
 
1.hideStatusbarAndTitlebar()statusbarとtitlebarを隠す.
?
1
2
3
4
5
6
7
8 private void hideStatusbarAndTitlebar() {      final Window win = getWindow();      // No Statusbar      win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,              WindowManager.LayoutParams.FLAG_FULLSCREEN);      // No Titlebar      requestWindowFeature(Window.FEATURE_NO_TITLE); }
2.画面表示モードを設定する.
activityでandroid:screenOrientationの値を設定します.Android:screenOrientationのプロパティには、unspecified(デフォルト値、システム判断状態によって自動的に切り替える)、The default valueの値があります.The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device. landscape,横スクリーンportrait,縦スクリーンuser(ユーザが現在設定するorientation値),The user's current preferred orientation.behind(次のActivityのorientation値)、The same orientation as the activity that's immediately beneath it in the activity stack.sensor(センサの方向)、The orientation determined by a physical orientation sensor.The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device. nosensor(センサを使用しない、この効果の差はunspecifiedに等しくない).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified"setting.
3.水平/垂直を中心とする方法.
parentのandroid:gravityを「center」に設定します.
4.現在の画面幅の高さを求める方法.
?
1
2
3 Display display = getWindowManager().getDefaultDisplay(); Config.screenWidth = display.getWidth(); Config.screenHeight = display.getHeight();