android 分辨率显示不全,Android笔记:多分辨率适配及碎片化问题解决方案总结

一、适配多分辨率

Screen characteristicQualifierDescription

SizesmallResources for small size screens.

normalResources for normal size screens. (This is the baseline size.)

largeResources for large size screens.

xlargeResources for extra large size screens.

DensityldpiResources for low-density (ldpi) screens (~120dpi).

mdpiResources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)

hdpiResources for high-density (hdpi) screens (~240dpi).

xhdpiResources for extra high-density (xhdpi) screens (~320dpi).

nodpiResources 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.

tvdpiResources 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 p_w_picpath for mdpi screens should be 133px x 133px for tvdpi.

OrientationlandResources for screens in the landscape orientation (wide aspect ratio).

portResources for screens in the portrait orientation (tall aspect ratio).

Aspect ratiolongResources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration.

notlongResources for use screens that have an aspect ratio that is similar to the baseline screen configuration.

关于布局文件适配的一些示例:res/layout/my_layout.xml// layout for normal screen size ("default")res/layout-small/my_layout.xml// layout for small screen sizeres/layout-large/my_layout.xml// layout for large screen sizeres/layout-xlarge/my_layout.xml// layout for extra large screen sizeres/layout-xlarge-land/my_layout.xml// layout for extra large in landscape orientationres/drawable-mdpi/my_icon.png// bitmap for medium densityres/drawable-hdpi/my_icon.png// bitmap for high densityres/drawable-xhdpi/my_icon.png// bitmap for extra high density

密度与尺寸定义的大概图示:

fc3b21671e8b44ad28ece399c2b112d7.png

2.关于屏幕大小的定义:xlarge screens are at least 960dp x 720dp

large screens are at least 640dp x 480dp

normal screens are at least 470dp x 320dp

small screens are at least 426dp x 320dp

在项目实作中,遇到一个问题,要对HVGA(320 * 480 px, density = 160), WVGA(480*800 px, density = 240) 和 QHD (540*960 px, density = 240) 进行适配, 换算成dp后,可以看到三种分辨率都是属于values-normal范围的,这下麻烦了,这三种屏幕尺寸差异很大,界面适配上必须要对应不同的值,怎么办呢?

解决方法很简单,实际上qualifier是可以配置多个的,之间以"-"连接。

将values-normal 分成两个目录,即values-normal-mdpi,  values-normal-hdpi, 其下分别对应相应的dimens.xml即可。values-normal-mdpi 对应 HVGA, values-normal-hdpi对应WVGA和QHD。

3.图标大小的设定

针对不同密度创建的图标,你应该遵循四个广义密度之间的3:4:6:8缩放比例。例如,如果你有一个48 x48像素的图标对应于mdpi,则其他尺寸应该是:36x36 for low-density

48x48 for medium-density

72x72 for high-density

96x96 for extra high-density

4.比较典型的屏幕宽度尺寸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).

5.尺寸与密度的一般对应

Low density (120), ldpiMedium density (160), mdpiHigh density (240), hdpiExtra high density (320), xhdpi

SmallscreenQVGA (240x320)480x640

NormalscreenWQVGA400 (240x400)

WQVGA432 (240x432)HVGA (320x480)WVGA800 (480x800)

WVGA854 (480x854) 600x1024640x960

LargescreenWVGA800** (480x800)

WVGA854** (480x854)WVGA800* (480x800)

WVGA854* (480x854) 600x1024

Extra Largescreen1024x600WXGA (1280x800)

6.一个比较有代表性的软件资源包结构图

c6d2e0f43a5a7b3f87e6e25623b0db1a.png

7.drawable-nodpi的作用

把一些不能被拉伸的图片放在 drawable-nodpi 中,此图片将不会被放大,以原大小显示。

但是宽和高要写wrap_content,不要写dip。

8.配置AndroidManifest.xml使应用支持多分辨率

android:largeScreens="true"

android:normalScreens="true"

android:smallScreens="true"

android:anyDensity="true"/>

9.Android屏幕图标尺寸一般规范

(1). 程序启动图标:

ldpi (120 dpi)  小屏    36 x 36 px

mdpi (160 dpi)  中屏    48 x 48 px

hdpi (240 dpi)  大屏    72 x 72 px

xhdpi (320 dpi) 特大屏  96 x 96 px

(2).底部菜单图标

9ed08e620fb74c420c02bcaafd84685d.png

大屏:

1. 完整图片(红色): 72 x 72 px

2. 图标(蓝色): 48 x 48 px

3. 图标外边框(粉色): 44 x 44 px

中屏:

1. 完整图片: 48 x 48 px

2. 图标: 32 x 32 px

3. 图标外边框: 30 x 30 px

小屏:

1. 完整图片: 36 x 36 px

2. 图标: 24 x 24 px

3. 图标外边框: 22 x 22 px

(3). 弹出对话框顶部图标

Low density screen (ldpi)        小屏  24 x 24 px

Medium density screen (mdpi)     中屏  32 x 32 px

High density screen (hdpi)       大屏  48 x 48 px

(4). 长列表内部列表项图标

Low density screen (ldpi)     小屏  24 x 24 px

Medium density screen (mdpi)  中屏  32 x 32 px

High density screen (hdpi)    大屏  48 x 48 px

(5). 底部或顶部tab标签图标

990e6dda780e0cf95badc8c98b84de8e.png

大屏 (hdpi):

1. 完整图片(红色): 48 x 48 px

2. 图标(蓝色): 42 x 42 px

中屏 (mdpi):

1. 完整图片: 32 x 32 px

2. 图标: 28 x 28 px

小屏(ldpi):

1. 完整图片: 24 x 24 px

2. 图标: 22 x 22 px

(6). 底部状态栏图标

ldpi (120 dpi)   小屏     18 x 18 px

mdpi (160 dpi)   中屏     24 x 24 px

hdpi (240 dpi)   大屏     36 x 36 px

xhdpi (320 dpi)  特大屏   48 x 48 px

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值