1.尽量使用dp设置控件的大小距离,文字使用sp,dp是和分辨率无关的
2.少用绝对布局,尽量使用相对布局
3.图片使用多路径 drawable_small drawable_large
4.不同大小和布局的情况下,布局差异大可以考虑使用 layout_large layout_small 多种布局
仔细看了一下android开发文档,基本了解android对多屏的开发支持。
| Ldpi (120) | Mdpi(160) | Hdpi(240) | Xhdpi(320) |
small | 1.90% | | 2.50% | |
QVGA(240*320) | 480x640 | |||
normal | 0.70% | 19.60% | 64.60% | 2.40% |
WQVGA400 (240x400) | HVGA(320x480) | WVGA800(480x800) | 640x960 | |
WQVGA432 (240x432) | | WVGA854(480x854) | | |
| | 600x1024 | | |
large | 0.20% | 2.30% | ||
WVGA800** (480x800) | WVGA800* (480x800) | |||
WVGA854** (480x854) | WVGA854* (480x854) | |||
| 600x1024 | |||
xlarge | 1024x600 | 5.80% | 1536x1152 | 2048x1536 |
WXGA (1280x800) | 1920x1152 | 2560x1536 | ||
1024x768 | 1920x1200 | 2560x1600 | ||
1280x768 | | |
什么是DPI:Dot Per Inch。 1英寸=2.54厘米
drawable-en-rUS-xhdpi
Screen characteristic | Qualifier | Description |
Size | small | Resources for small size screens. |
normal | Resources for normal size screens. (This is the baseline size.) | |
large | Resources for large size screens. | |
xlarge | Resources for extra large size screens. | |
Density | ldpi | Resources for low-density (ldpi) screens (~120dpi). |
mdpi | Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) | |
hdpi | Resources for high-density (hdpi) screens (~240dpi). | |
xhdpi | Resources for extra high-density (xhdpi) screens (~320dpi). | |
nodpi | Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density. | |
tvdpi | Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi. | |
Orientation | land | Resources for screens in the landscape orientation (wide aspect ratio). |
port | Resources for screens in the portrait orientation (tall aspect ratio). | |
Aspect ratio | long | Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration. |
notlong | Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration. |
举例:
res/layout/my_layout.xml
res/layout-small/my_layout.xml
res/layout-large/my_layout.xml
res/layout-xlarge/my_layout.xml
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscapeorientation
res/drawable-mdpi/my_icon.png
res/drawable-hdpi/my_icon.png
res/drawable-xhdpi/my_icon.png
其它:
:适当使用 Nine-Patchbitmap files,可以减少不同密度图片的工作量。
:res/drawable-nodpi/icon.png nodpi指的是不进行缩放。这个可能在某些特殊场景会用到。
:aspect 是否宽屏
根据上面的原理,可以确定简单的策略:
同一个软件,要达到此目的,显然不能使用px,因为他会导致效果不同,如果使用dp,因为它是按设备的dpi进行了运算,刚
好将dpi的不同体现到了点阵上,因而达到相同效果的目的。
drawable/
下。