Android-Studio之mipmap目录和drawable目录详解

原创 2015年11月20日 10:30:31

简单说一下:

使用上没有任何区别,你把它当drawable用就好了。

但是用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().

应用场景:

If you know that you are going to draw this bitmap at less than 50% of its original size, you may be able to obtain a higher quality by turning this property on. Note that if the renderer respects this hint it might have to allocate extra memory to hold the mipmap levels for this bitmap.

一个应用实例:

Nexus 6
Screen
The Nexus 6 boasts an impressive 5.96” Quad HD screen display at a resolution of 2560 x 1440 (493 ppi). This translates to ~ 730 x 410 dp (density independent pixels).

Check your assets
It has a quantized density of 560 dpi, which falls in between the xxhdpi and xxxhdpi primary density buckets. For the Nexus 6, the platform will scale down xxxhdpi assets, but if those aren’t available, then it will scale up xxhdpi assets.
Provide at least an xxxhdpi app icon because devices can display large app icons on the launcher. 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. For example, an xxxhdpi app icon can be used on the launcher for an xxhdpi device.
res/
mipmap-mdpi/
ic_launcher.png
mipmap-hdpi/
ic_launcher.png
mipmap-xhdpi/
ic_launcher.png
mipmap-xxhdpi/
ic_launcher.png
mipmap-xxxhdpi/
ic_launcher.png # App icon used on Nexus 6 device launcher
Choosing to add xxxhdpi versions for the rest of your assets will provide a sharper visual experience on the Nexus 6, but does increase apk size, so you should make an appropriate decision for your app.

res/
drawable-mdpi/
ic_sunny.png
drawable-hdpi/
ic_sunny.png
drawable-xhdpi/
ic_sunny.png
drawable-xxhdpi/ # Fall back to these if xxxhdpi versions aren’t available
ic_sunny.png
drawable-xxxhdpi/ # Higher resolution assets for Nexus 6
ic_sunny.png

总结

这个实例总结一下是这样:

Nexus 6 有 493 ppi,它刚好在 xxhdpi和xxxhdpi之间,所以显示的时候需要对xxxhdpi的资源进行缩小,如果你用了mipmap-xxxhdpi,那么这里会对sclae有一个优化,性能更好,占用内存更少。所以现在官方推荐使用mipmap:

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.

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

从事Android 开发的工程师们一直以为都在讨论一个问题,那就是图片到底应该放在Android Studio软件drawable文件夹下,还是应该放在mipmap下?今天把网络上出现的讨论做一个小小...

Java 代码调用 Android studio mipmap图片资源

今天有人问在Java代码中如何调用mipmap下的图片资源,整了一下,贴出来,算是给自己记得笔记啦!不多说直接上图。

Android Icon drawable-hdpi drawable-xhdpi drawable-xxhdpi drawable-xxxhdpi

Android Icon Size and Location for Apps DENSITY SIZE LOCATION RATIO SCREEN MARGIN XXXH...

Android Studio上 drawable与mipmap的区别

两者在使用上没有区别,可以把mipmap当做drawable来用,但mipmap比drawable缩放的性能更好。 所以最适合的方式就是: mipmap存放图片资源,drawable存放s...

【Android应用开发】Android Studio - MAC 版 - 快捷键详解

Android Studio 快捷键 MAC 版

Android项目中的mipmap文件夹是什么?怎么用?和drawable文件夹有什么区别?

Android项目中的mipmap文件夹是什么?怎么用?和drawable文件夹有什么区别?

Android Studio下drawable图标和mipmap图标详解

创建drawable图标新建一个Android Studio项目,并将任务视图切换到“Project”下,这时可以看到,系统在res目录下,为我们创建了4个对应的drawable文件夹,如下图所示。 ...

mipmap和drawable文件夹的区别

mipmap和drawable文件夹的区别

mipmap 和 drawable 的区别

android 在 API level 17 加入了 mipmap 技术,对 bitmap 图片的渲染支持 mipmap 技术,来提高渲染的速度和质量。 mipmap 和 drawable 的区别

第一行代码第二版(郭霖著)笔记之第三章(UI开发的点点滴滴)

本篇笔记主要记录了Android开发中的“常用控件”,“基本布局”:“线性布局”,“相对布局”,“百分比布局”,“自定义控件”,“ListView”,“RecyclerView”,“Nine-Patc...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)