從事Android 開發(fā)的工程師們一直以為都在討論一個(gè)問題,那就是圖片到底應(yīng)該放在android Studio軟件drawable文件夾下,還是應(yīng)該放在mipmap下?今天把網(wǎng)絡(luò)上出現(xiàn)的討論做一個(gè)小小的梳理,如果哪里不正確還請指正,文章中會(huì)引用一些其他博客的字段,在文章的末尾都會(huì)把轉(zhuǎn)載的地址附上。
支持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.
認(rèn)為圖片放在drawable文件夾下,分為幾個(gè)不同分辨率的文件夾,而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 class—Android 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().
認(rèn)為圖片應(yīng)該放在mipmap文件夾下,理由就是那句標(biāo)紅的英文文字。
那圖片到底應(yīng)該哪個(gè)文件夾下呢?有問題找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: 我注意到當(dāng)創(chuàng)建新的工程時(shí),得到了下面的目錄層級(jí):
mipmap folders for diffrent DPIs, No more diffrent DPIs drawable folders. 4個(gè)不同分辨率的mipmap文件夾,與不同DPI的drawable文件夾沒啥區(qū)別。 Should I put all my resources in the mipmap folders, or just the app icon? 我應(yīng)該把所有資源都放到mipmap文件夾么?或者只放應(yīng)用的圖標(biāo)?
答案: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文件夾只放應(yīng)用圖標(biāo)。其他需要使用的drawable資源象之前一樣放到對應(yīng)的drawable文件夾。
答案的出處來自Google的博文:
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.
應(yīng)用的啟動(dòng)圖標(biāo)最好放到mipmap文件夾(不是drawable文件夾),因?yàn)樗鼈冇迷诓煌直媛实脑O(shè)備上。
回答截圖如下:
至于支持圖片放在mipmap下的朋友們,應(yīng)該看看一下截圖,相信就會(huì)明白到底圖片放在哪個(gè)文件夾。