スクリーンサイズごとにレイアウトxmlを切り替える方法について

Screen-size Buckets

OS3.1までの方法。

buckets dp 具体的な機種
small 426dp × 320dp QVGA[320 * 240] + ldpi = 426*320dp
normal 470dp × 320dp
large 640dp × 480dp WVGA[800 * 480] + mdpi(Dell Streak)、7 インチ タブレット全般。
xlarge 960dp × 720dp WXGA[1280*800] + mdpi (Xoomなどの典型的な10inch tablet)

初代Galaxy Tabは、[1024*600]+hdpi=682*400dpで本来はnormalだが、フレームワークのミスによりlargeとして出荷されてしまった。

The original Samsung Galaxy Tab is an interesting case. Physically it is a 1024x600 7” screen and thus classified as “large”. However the device configures its screen as hdpi, which means after applying the appropriate ⅔ scaling factor the actual space on the screen is 682dp x 400dp. This actually moves it out of the “large” bucket and into a “normal” screen size. The Tab actually reports that it is “large”; this was a mistake in the framework’s computation of the size for that device that we made. Today no devices should ship like this.
Android Developers Blog: New Tools For Managing Screen Sizes

Numeric Selectors

OS 3.2から、指定可能になった方法。

dp type 解釈
320 a phone screen(240*320 ldpi, 320*480 mdpi, 480*800 hdpi, etc) 短辺が320dp
480 a tweener tablet like the Streak(480*800 mdpi) 短辺が480dp
600 7inch tablet(600 * 1024) 短辺が600dp
720 10inch tablet(720 * 1280, 800*1280, etc) 短辺が720dp以上

Combinations and Versions

とりあえず、phoneとtabletのレイアウト対応は下記のようにする。

res/layout/main_activity.xml # For phones
res/layout-xlarge/main_activity.xml # For pre-3.2 tablets
res/layout-sw600dp/main_activity.xml # For 3.2 and up tablets

ただし上記の方法だと、xlargeとsw600dpが共通の場合に冗長になってしまう。
そこでvaluesを使う方法がある。

res/values-xlarge/layout.xml
res/values-sw600dp/layout.xml

NewsReaderの場合

valuesフォルダ layout 対応するレイアウト
values onepane_with_bar phone
values-sw600dp-port onepanes OS3.2以上、7インチ以上のタブレット
values-xlarge-port twopanes_narrow 0S3.2未満、7(?)インチ以上のタブレット
values-xlarge-land twopanes OS3.2未満、7(?)インチ以上のタブレット
values-sw600dp-land twopanes OS3.2以上、7インチ以上のタブレット

※values-v11は、3.0以降のphoneにstyle Holoを指定するためのようだ。

具体例

1280 * 800 OS3.2のタブレット

フォルダ 適用レイアウト
layout, layout-large layout-large
layout, layout-large, layout-xlarge layout-xlarge
layout, layout-large, layout-xlarge, layout-sw600dp layout-sw600dp
layout, layout-large, layout-xlarge, layout-sw600dp, layout-sw720dp layout-sw720dp

OS3.2以降の場合は、swがあればlarge/xlargeより優先されるということ?