2016年02月03日
Android 手机分辨率的奇葩程度到让人绝望,令人发指,作为一个Android dev 自然也是不能忽视这个问题的!!!
我们可以用多个layout目录对不同分辨率进行单独布局,如下:
酱紫:
ldpi:240x320
mdpi:320x480
hdpi:480x800、480x854
xhdpi:至少960×720
xxhdpi:1280×720
或者酱紫:
- layout-large-mdpi (1024x600)
- layout-large-tvdpi (800x1280)
- layout-large-xhdpi (1200x1920)
- layout-xlarge-mdpi (1280x800)
- layout-xlarge-xhdpi (2560x1600)
- layout-640x360
- layout-800x480
然后与Layout对应的,drawable也是分分辨率的:
- res/drawable (default)res/drawable-ldpi/ (240x320 and nearer resolution)
- res/drawable-mdpi/ (320x480 and nearer resolution)
- res/drawable-hdpi/ (480x800, 540x960 and nearer resolution)
- res/drawable-xhdpi/ (720x1280 - Samsung S3, Micromax Canvas HD etc)
- res/drawable-xxhdpi/ (1080x1920 - Samsung S4, HTC one, Nexus 5, etc)
使用不同的Layout对应的适配工作量会随之增加,工作中我们使用不同的values来对应layout中的值:
- res/values/dimens.xml(default)
- res/values-ldpi/dimens.xml (240x320 and nearer resolution)
- res/values-mdpi/dimens.xml (320x480 and nearer resolution)
- res/values-hdpi/dimens.xml (480x800, 540x960 and nearer resolution)
- res/values-xhdpi/dimens.xml (720x1280 - Samsung S3, Micromax Canvas HD, etc)
- res/values-xxhdpi/dimens.xml (1080x1920 - Samsung S4, HTC one, etc)
- res/values-large/dimens.xml (480x800)
- res/values-large-mdpi/dimens.xml (600x1024)
- res/values-sw600dp/dimens.xml (600x1024)
- res/values-sw720dp/dimens.xml (800x1280)
- res/values-xlarge-xhdpi/dimens.xml (2560x1600 - Nexus 10")
- res/values-large-xhdpi/dimens.xml (1200x1920 - Nexus 7"(latest))
----------------------------华丽的分隔线---------------------------
密度: