mipmap和drawable区别
2015-12-19 15:03
731 查看
Android Studio中会看到mipmap和drawable两个目录,在网上搜寻两个差别是,会得到以下答案:Android Studio一般都把图片放在mipmap中。但是当我把9patch图片文件放在mipmap中时,会发现Android Studio无法识别到9patch文件的情况,最后发现是因为9patch文件需要放在drawable文件夹下面的原因。
于是出于好奇,就去搜了图片放在mipmap文件夹和drawable文件夹中的区别,因此就去搜了一下,转载于下。
cite:http://segmentfault.com/q/1010000002603418
使用上没有任何区别,你把它当drawable用就好了。
但是用mipmap系统会在缩放上提供一定的性能优化。
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().
to hold the mipmap levels for this bitmap.
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.
[/code]
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.
[/code]
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.
于是出于好奇,就去搜了图片放在mipmap文件夹和drawable文件夹中的区别,因此就去搜了一下,转载于下。
cite:http://segmentfault.com/q/1010000002603418
使用上没有任何区别,你把它当drawable用就好了。
但是用mipmap系统会在缩放上提供一定的性能优化。
官方介绍:
Mipmapping for drawablesUsing 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 memoryto hold the mipmap levels for this bitmap.
一个应用实例:
Nexus 6Screen
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
[/code]
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
[/code]
总结
这个实例总结一下是这样: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.
相关文章推荐
- rpm 工具
- 从程序员的角度看产品经理的逻辑与设计能力
- npm err错误
- NMOS和PMOS
- JSeparator类 JPopupMenu类
- AEAI BPM流程集成平台V3.0.2版本开源发布
- AEAI BPM流程集成平台V3.0.2版本开源发布
- AEAI BPM流程集成平台V3.0.2版本开源发布
- Activiti与JBPM5的技术层面对比
- npm、spm、bower 这三个包管理器的异同
- CM Development
- ACM/ICPM2014鞍山现场赛D Galaxy (HDU 5073)
- alien 进行rpm 包和deb 包之间的转换
- development
- RPM-GPG-KEY详解
- 产品经理入门之三步分解需求
- Power management interface(PM API)
- rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
- PMCAFF问答龙虎榜,大神云集,等你挑战
- 使用canvas.drawBitmapMesh扭曲图像