「MonoGame (Xamarin.Android)で画面の向きを指定する」の版間の差分

提供: MonoBook
ナビゲーションに移動 検索に移動
 
9行目: 9行目:
 
* 縦画面に固定したい場合は「ScreenOrientation.Portrait」を指定する。
 
* 縦画面に固定したい場合は「ScreenOrientation.Portrait」を指定する。
  
<source>
+
<source lang="csharp">
    [Activity(Label = "Game1",
+
[Activity(Label = "Game1",
              MainLauncher = true,
+
            MainLauncher = true,
              Icon = "@drawable/icon",
+
            Icon = "@drawable/icon",
              Theme = "@style/Theme.Splash",
+
            Theme = "@style/Theme.Splash",
              AlwaysRetainTaskState = true,
+
            AlwaysRetainTaskState = true,
              LaunchMode = LaunchMode.SingleInstance,
+
            LaunchMode = LaunchMode.SingleInstance,
              ScreenOrientation = ScreenOrientation.Portrait,
+
            ScreenOrientation = ScreenOrientation.Portrait,
              ConfigurationChanges = ConfigChanges.Orientation |
+
            ConfigurationChanges = ConfigChanges.Orientation |
                                      ConfigChanges.KeyboardHidden |
+
                                    ConfigChanges.KeyboardHidden |
                                      ConfigChanges.Keyboard |
+
                                    ConfigChanges.Keyboard |
                                      ConfigChanges.ScreenSize)]
+
                                    ConfigChanges.ScreenSize)]
    public class GameActivity : AndroidGameActivity
+
public class GameActivity : AndroidGameActivity
    {
+
{
    }
+
}
 
</source>
 
</source>
  

2021年4月20日 (火) 07:17時点における最新版


MonoGame (Xamarin.Android)プロジェクトを新規作成すると必ずエントリポイントとなるActivityクラスが作られる。 このActivityクラスの「ScreenOrientation属性」を変更する。 基本的には至って普通のXamarin.Androidでの方法と同じである。

  • 初期値は「ScreenOrientation.FullUser」となっておりスマホの回転にあわせグルグル回る。
  • 横画面に固定したい場合は「ScreenOrientation.Landscape」を指定する。
  • 縦画面に固定したい場合は「ScreenOrientation.Portrait」を指定する。
[Activity(Label = "Game1",
            MainLauncher = true,
            Icon = "@drawable/icon",
            Theme = "@style/Theme.Splash",
            AlwaysRetainTaskState = true,
            LaunchMode = LaunchMode.SingleInstance,
            ScreenOrientation = ScreenOrientation.Portrait,
            ConfigurationChanges = ConfigChanges.Orientation |
                                    ConfigChanges.KeyboardHidden |
                                    ConfigChanges.Keyboard |
                                    ConfigChanges.ScreenSize)]
public class GameActivity : AndroidGameActivity
{
}

関連項目[編集 | ソースを編集]