有很多朋友在android studio下生成项目时会发现有mipmap文件夹,而相对应的drawable不见了,于是开始发大招,百度,google,多数得到的回馈是mipmap优化了渲染性能,建议用mipmap取代drawable,这些纯属误导,还是把人家官方的描述拿出来把,这样权威些,原文地址:http://developer.android.com/tools/projects/index.html#mipmap
部分描述:
Different home screen launcher apps on different devices show app launcher icons at variousresolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscalea 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.
res/mipmap/
folders(for example
res/mipmap-mdpi/
and
res/mipmap-xxxhdpi/
). The
mipmap/
folders replace the
drawable/
folders for launcher icons. Forxxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of theicons to enhance the visual experience of the icons on higher resolution device
就不详细翻译了,大致意思呢就是mipmap是专门放置启动图标的,是由于应用的资源优化技术会删除没有使用的相对应屏幕密度的drawable的图片资源。
如果手机介于两个密度之间就可能会导致系统留下不合适的图片进行缩放等操作而导致图标模糊。而使用mipmap,android系统会始终保留这些资源使得系统能够挑选更好分辨率的图标进行显示。
在开发者关于屏幕适配的文章中,还有一句话更能说明mipmap的终极用途
Note: The mipmap-xxxhdpi
qualifier is necessary only to provide a launcher icon that can appear larger than usual on anxxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.
“only” fro launcher icon,也可以打消很多人想要把其他资源也放到mipmap下的疑问
经过自己的测试,将其他图片资源放入mipmap也可以,除了.9图片,还有引入的时候要用@mipmap或者R.mipmap.
在这里我还有个“?”,按照第一段开发者里的描述,如果把资源都放到mipmap中,系统会保留所有的资源而不去删除会不会导致性能等问题?如果有知道的大牛还请指教?