mipmap vs drawable

来源:互联网 发布:怎么在淘宝上找同款 编辑:程序博客网 时间:2024/05/16 09:50

现在用Android Studio进行安卓开发,创建项目时会自动创建mipmap文件夹,打开之后里面存放的应用程序的启动图标,这种情况下,问题就来了,默认将启动图标放在了mipmap文件夹下,其他的图片该怎么存放呢?答案是:像以前一样放在drawable文件夹下。接着又是一个问题:为什么这么放? 我也困惑了好久,直到再次遇见这个问题,才决定弄明白,查看了一些资料做了如下解释:

  • Google对于这两个文件夹的解释:

    • 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.
    • 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.
  • stackoverflow上的解释:
    The mipmap folders are for placing your app icons in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.

看完上面的解释之后,总结出以下原因:Android的分辨率不是很规范,图片的适配只能大致适应一个范围,并且在应用程序识别了目标手机的分辨率之后会对图片资源进行优化,把未用到的资源删除,这种情况下,启动图标有可能被拉伸或者缩小,显示在桌面上之后出现模糊的情况,而mipmap下的图片会通过Mipmap纹理技术进行优化 ,以最佳的分辨率显示在桌面上。所以建议把icon放在mipmap下,其他的图片存放在drawable文件夹下,drawable文件夹是存放一些xml(如selector)和bitmap(.jpg .png .gif)。

了解Mipmap纹理技术请参考以下链接:

Mipmap纹理技术

0 0
原创粉丝点击