Drawable和Mipmap的區別


在android studio 1.1版本中,新建新工程,在res目錄下就會自動生成幾個mipmap目錄,這幾個目錄存儲着app的launcher圖標,在之前版本的AS中,launcher是存儲在drawable目錄下的,那AS1.1為什么要引入mipmap呢,我們先看看官方的文檔:

Different home screen launcher apps on different devices show app launcher icons at various resolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscale a 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.

Make sure launcher apps show a high-resolution icon for your app by moving all densities of your launcher icons to density-specific res/mipmap/ folders (for example res/mipmap-mdpi/ and res/mipmap-xxxhdpi/). The mipmap/folders replace the drawable/ folders for launcher icons. For xxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of the icons to enhance the visual experience of the icons on higher resolution devices.

Note: Even if you build a single APK for all devices, it is still best practice to move your launcher icons to the mipmap/folders.

從說明中可以看到,google推薦將launcher icon放在mipmap目錄中,因為mipmap對圖片進行了很好的優化,我們沒有必要深究怎么優化的,既然官方推薦使用mipmap保存icon,那我們在項目中就將launcher icon放在mipmap目錄下。

注意,mipmap只是針對與launcher icon的,我們只能在AndroidMainfest.xml才能使用

android:icon="@mipmap/ic_launcher"

在其它xml文件中是無法使用@mipmap/的,這也驗證了mipmap只是針對於launcher icon存在的,所以其它的資源圖片我們還是應該放在drawable目錄下。

參考:1.https://developer.android.com/tools/projects/index.html#mipmap

          2.https://androidbycode.wordpress.com/2015/02/14/goodbye-launcher-drawables-hello-mipmaps/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM