:
res/layout/ -- default
res/layout-port/ -- portrait for any screen size
res/layout-xlarge/ -- any orientation on xlarge screens
res/layout-xlarge-land/ -- landscape on xlarge screens
は小さい画面サイズのためのあなたの肖像画のみのレイアウトにlayout-port
ディレクトリを使用して、あなたが同じレイアウトファイルを使用したい場合はlayout-xlarge
ディレクトリにXLARGEのレイアウトを追加xlargeの縦と横の場合は、layout-xlarge-land
とlayout-xlarge-port
になります。向きに応じて異なるレイアウトファイルが必要な場合は、
次に、小さいスクリーンデバイス上でランドスケープに回転すると、OSはランドスケープレイアウトを読み込もうとしますが、一致するものがないために失敗し、Resources.NotFoundException
がスローされます。あなたはしかし、その例外をキャッチし、Activity.setRequestedOrientation()
を使用して、それらの例には、ポートレートモードに活動を強制することができます。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.titlescreen);
} catch (Resources.NotFoundException e) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
return;
}
[...]
}
、その後の活動は、ポートレートモードで再現されることになりますし、それが再び変更しようとしないことのでsetRequestedOrientation()
を使用すると、方向センサーが上書きされます。
私は同じ問題を抱えていて、この非常に主題についてブログの記事を書きました。 私はいくつかの解決策を提示しています: http://androidblogger.blogspot.com/2011/08/orientation-for-both-phones-and-tablets.html – alocaly