首先,3.2以前是设置不同的small , normal, large, xlarge来解决
3.2以后通过设置最小的DP长度或者宽度来设置,比如layout-sw600dp
To help you target some of your designs for different types of devices, here are somenumbers for typical screen widths:
- 320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
- 480dp: a tweener tablet like the Streak (480x800 mdpi).
- 600dp: a 7” tablet (600x1024 mdpi).
- 720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).
res/layout/main_activity.xml # For handsets res/layout-sw600dp/main_activity.xml # For tablets
还要在manifest里设置下最小的那个长度或者宽度。
<manifest ... > <supports-screens android:requiresSmallestWidthDp="600" /> ... </manifest>
- Use
wrap_content
,fill_parent
, ordp
units when specifyingdimensions in an XML layout file - Do not use hard coded pixel values in your application code
- Do not use
AbsoluteLayout
(it's deprecated) - Supply alternative bitmap drawables for different screen densities
2 不要用固定的PX为单位
3. 不要用绝对布局
4. 设置不同分辨率的图片自适应
Low density (120), ldpi | Medium density (160), mdpi | High density (240), hdpi | Extra high density (320), xhdpi | |
---|---|---|---|---|
Small screen | QVGA (240x320) | 480x640 | ||
Normal screen | WQVGA400 (240x400) WQVGA432 (240x432) | HVGA (320x480) | WVGA800 (480x800) WVGA854 (480x854) 600x1024 | 640x960 |
Large screen | WVGA800** (480x800) WVGA854** (480x854) | WVGA800* (480x800) WVGA854* (480x854) 600x1024 | ||
Extra Large screen | 1024x600 | WXGA (1280x800)† 1024x768 1280x768 | 1536x1152 1920x1152 1920x1200 | 2048x1536 2560x1536 2560x1600 |
* To emulate this configuration, specify acustom density of 160 when creating an AVD that uses a WVGA800 or WVGA854 skin. ** To emulate this configuration, specify a custom density of 120 when creating an AVD thatuses a WVGA800 or WVGA854 skin. † This skin is available with the Android 3.0 platform |
用以上属性来测试不同屏幕效果