「Xamarin.Androidで画面の向きを固定する」の版間の差分
Administrator (トーク | 投稿記録) |
Administrator (トーク | 投稿記録) |
||
| 4行目: | 4行目: | ||
縦方向に固定する場合。 | 縦方向に固定する場合。 | ||
<source lang="csharp"> | <source lang="csharp"> | ||
public class Activity1 : AndroidGameActivity | |||
{ | |||
protected override void OnCreate(Bundle bundle) | |||
{ | { | ||
base.OnCreate(bundle); | |||
// 以下のRequestedOrientationプロパティに設定する方法だとダメ。 | |||
// 起動時に一瞬だけ横になりMonoGameの初期化ルーチンで画面サイズの情報がバグる。 | |||
this.RequestedOrientation = ScreenOrientation.Portrait; | |||
var g = new GameMain(); | |||
SetContentView(g.Services.GetService<View>()); | |||
g.Run(); | |||
} | |||
// RequestedOrientationプロパティをoverrideする方法だと完璧に動くようだ。 | |||
public override ScreenOrientation RequestedOrientation | |||
{ | |||
get | |||
{ | |||
return ScreenOrientation.Portrait; | |||
} | } | ||
set | |||
{ | { | ||
base.RequestedOrientation = ScreenOrientation.Portrait; | |||
} | } | ||
} | } | ||
} | |||
</source> | </source> | ||