Drawable和Mipmap的区别

在android studio 1.1版本中,新建新工程,在res目录下就会自动生成几个mipmap目录,这几个目录存储着app的launcher图标,在之前版本的AS中,launcher是存储在drawable目录下的,那AS1.1为什么要引入mipmap呢,我们先看看官方的文档:

Different home screen launcher apps on different devices show app launcher icons at various resolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscale a lower-resolution icon for display. To avoid these display issues, apps should use the mipmap/ resource folders for launcher icons. The Android system preserves these resources regardless of density stripping, and ensures that launcher apps can pick icons with the best resolution for display.

Make sure launcher apps show a high-resolution icon for your app by moving all densities of your launcher icons to density-specific res/mipmap/ folders (for example res/mipmap-mdpi/ and res/mipmap-xxxhdpi/). The mipmap/folders replace the drawable/ folders for launcher icons. For xxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of the icons to enhance the visual experience of the icons on higher resolution devices.

Note: Even if you build a single APK for all devices, it is still best practice to move your launcher icons to the mipmap/folders.

从说明中可以看到,google推荐将launcher icon放在mipmap目录中,因为mipmap对图片进行了很好的优化,我们没有必要深究怎么优化的,既然官方推荐使用mipmap保存icon,那我们在项目中就将launcher icon放在mipmap目录下。

注意,mipmap只是针对与launcher icon的,我们只能在AndroidMainfest.xml才能使用

android:icon="@mipmap/ic_launcher"

在其它xml文件中是无法使用@mipmap/的,这也验证了mipmap只是针对于launcher icon存在的,所以其它的资源图片我们还是应该放在drawable目录下。

参考:1.https://developer.android.com/tools/projects/index.html#mipmap

          2.https://androidbycode.wordpress.com/2015/02/14/goodbye-launcher-drawables-hello-mipmaps/

posted @ 2015-07-23 12:39  mooreliu  阅读(3365)  评论(0编辑  收藏  举报