您的位置:首页 > 移动开发 > Android开发

Android Studio中mipmap目录和drawable目录有什么区别

2015-08-31 16:18 507 查看
使用Android Studio开发时发现有2个目录可以放置图片: mipmap vs drawable,那么他们有什么区别呢?该选择哪个呢?

这里网罗各位大神的答案,共同学习:

答案1:

图片还是放在drawable文件夹下吧,mipmap只放launcher icons就好了。

Google官方有介绍:Managing
Projects Overview

drawable/

For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects
that contain multiple states (normal, pressed, or focused). See the Drawable resource
type.

mipmap/

For app launcher icons. The Android system retains the resources in this folder (and density-specific folders such as
mipmap-xxxhdpi) regardless of the screen resolution of the device where your app is installed. This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen. For more information about using the mipmap folders,
see Managing Launcher Icons as mipmap Resources

答案2:

Mipmaps早在Android2.2+就可以用了,但是直到4.3 google才强烈建议使用。把图片放到mipmaps可以提高系统渲染图片的速度,提高图片质量,减少GPU压力。so,do it

答案3:

我也想问这个问题。。。

经过我的研究,我认为 mipmap 支持多尺度缩放效果很好,比如一个 200*200 的图片缩放,如果我们使用 mipmap 那么系统会根据当前缩放范围选择 mipmap 里面恰当的图片,而不是想 drawable 目录下是根据当前设备的屏幕密度选择恰当的图片。如果一个
imageview 有缩放动画,使用 drawable 下的图片,会一直使用一张,来缩放图片实现 imageview 缩放动画,如果使用 mipmap 会根据缩放程度自动选择比当前分辨率大而又最接近当前分辨率的图片来做缩放处理,这样就实现了 google 官方文档中描述的更好视觉效果,更高效率的目的。这也和 mipmap 这个技术的本身含义吻合,除非 google 乱取名字。而 google 文档里面说 laucher icon 使用 mipmap 我认为是因为 laucher icon 在 laucher
app 里面可能有动画,或者有的 laucher app 使用的 laucher icon 分辨率比 google 规定的大,导致使用 drawable 下面的图片会放大,而显示效果不好。

总结:

保守点跟着官方文档走:普通图片放drawable,icon图标放mipmap。既然mipmap自适应缩放效果好,那就把一些动画的图片也放进去吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: