您的位置:首页 > 其它

关于安卓屏幕适配的个人风险

2014-10-31 11:05 330 查看


适配的图片

src : http://developer.android.com/training/basics/supporting-devices/screens.html
查看官方给的建议,就是我们的图片是需要有一个比例的。比例如下

xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75

例如我们放了一张200x200 的图片在drawable- xhdpi文件加下,那么为了兼容,相应的我们需要放150x150
在 hdpi, 100x100 的在 mdpi, 和 75x75 在 ldpi 文件夹下!但 Low-density
(ldpi)文件不一定是必须的,因为当你提供了Hdpi文件的时候。系统会自动的缩小一半来适配LDPI的屏幕。碉堡了,所以我们平时在反编译辨认的apk时候会看到,其实很多文件是放在Hdpi目录下,大概就是这个道理啦

 resources
aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.
--------

当然我们适配的时候,还是需要考虑文件的命名的规范,下面是谷歌官方给出的一些建议

学安卓的都看得懂,就不翻译了!

Try to name files so that related assets will group together inside a directory when they are sorted alphabetically. In
particular, it helps to use a common prefix for each icon type. For example:


Asset TypePrefixExample
Icons
ic_
ic_star.png
Launcher icons
ic_launcher
ic_launcher_calendar.png
Menu icons and Action Bar icons
ic_menu
ic_menu_archive.png
Status bar icons
ic_stat_notify
ic_stat_notify_msg.png
Tab icons
ic_tab
ic_tab_recent.png
Dialog icons
ic_dialog
ic_dialog_info.png
Note that you are not required to use a shared prefix of any type—doing so is for your convenience only.

Create Different Bitmaps

You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low, medium, high and extra-high density. This helps you achieve good graphical quality and performance on all screen densities.

To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75

This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.

Then, place the files in the appropriate drawable resource directory:
MyProject/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png


Any time you reference 
@drawable/awesomeimage
, the system selects the appropriate bitmap based on the screen's density.

---------------


 适配文字
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: