Android Studio的图片到底是放在drawable还是mipmap呢

     从事Android 开发的工程师们一直以为都在讨论一个问题,那就是图片到底应该放在Android Studio软件drawable文件夹下,还是应该放在mipmap下?今天把网络上出现的讨论做一个小小的梳理,如果哪里不正确还请指正,文章中会引用一些其他博客的字段,在文章的末尾都会把转载的地址附上。

    支持drawable的朋友们的理论出处如下:
     谷歌官方:
 
   
    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.

      认为图片放在drawable文件夹下,分为几个不同分辨率的文件夹,而app icons 放在mipmap下,而且mipmap只放mipmap。
      支持mipmap的朋友们的理论出处如下:
 
   
    Mipmapping for drawables
    Using a mipmap as the source for your bitmap or drawable is a simple way to provide a quality image and various image scales, which can be particularly useful if you expect your image to be scaled during an animation.
    Android 4.2 (API level 17) added support for mipmaps in the Bitmap classAndroid swaps the mip images in your Bitmap when you've supplied a mipmap source and have enabled setHasMipMap(). Now in Android 4.3, you can enable mipmaps for a BitmapDrawable object as well, by providing a mipmap asset and setting the android:mipMap attribute in a bitmap resource file or by calling hasMipMap().

      认为图片应该放在mipmap文件夹下,理由就是那句标红的英文文字。

      那图片到底应该哪个文件夹下呢?有问题找stackoverflow 。

    我们可以看到这样的提问,问题是:I’m working with android studio 1.1 Preview 1 我使用android studio 1.1 Preview 1版本工作。 And I noticed that when I create a new project I’m getting next hierarchy: 我注意到当创建新的工程时,得到了下面的目录层级:  

Android Studio的图片到底是放在drawable还是mipmap呢_第1张图片 

        mipmap folders for diffrent DPIs, No more diffrent DPIs drawable folders. 4个不同分辨率的mipmap文件夹,与不同DPI的drawable文件夹没啥区别。 Should I put all my resources in the mipmap folders, or just the app icon? 我应该把所有资源都放到mipmap文件夹么?或者只放应用的图标? 
        答案: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. mipmap文件夹只放应用图标。其他需要使用的drawable资源象之前一样放到对应的drawable文件夹。

     答案的出处来自Google的博文:

 
    
Its best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the devices current density.
       应用的启动图标最好放到mipmap文件夹(不是drawable文件夹),因为它们用在不同分辨率的设备上。 
      回答截图如下:
Android Studio的图片到底是放在drawable还是mipmap呢_第2张图片
Android Studio的图片到底是放在drawable还是mipmap呢_第3张图片
Android Studio的图片到底是放在drawable还是mipmap呢_第4张图片

至于支持图片放在mipmap下的朋友们,应该看看一下截图,相信就会明白到底图片放在哪个文件夹。

综上:图片应该放在drawable文件夹下,而mipmap文件夹只适合放app icons ,之前Android Studio 1.1版本的时候app icons上上传几个不同分辨率的图片,

而现在Android Studio 2.1.2 已经把mipmap文件夹默认分为了不同分辨率的文件夹,方便适配。


参考:http://stackoverflow.com/questions/23935810/mipmap-drawables-for-icons

参考:http://stackoverflow.com/questions/28065267/mipmap-vs-drawable-folders 

参考:http://blog.csdn.net/lihenair/article/details/49871453

你可能感兴趣的:(Android基础)