图标的 Mipmap 可绘制对象 [英] Mipmap drawables for icons

查看:46
本文介绍了图标的 Mipmap 可绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Android 4.3 (Jelly Bean) 开始,我们现在可以使用 res/mipmap 文件夹来存储mipmap"图像.

例如,Android 版 Chrome 将其图标存储在这些文件夹中,而不是更普通的 res/drawable 文件夹.

这些 mipmap 图像与其他熟悉的可绘制图像有何不同?

我看到在我的清单中,我们使用了 @mipmap/ 限定符,而不是 @drawable/,这在给定资源文件夹名称的情况下是有意义的:

在谈到 Nexus 6 屏幕密度时,作者写道:

<块引用>

最好的做法是将你的应用程序图标放在 mipmap- 文件夹中(而不是drawable- 文件夹),因为它们的分辨率不同于器件的电流密度.例如,xxxhdpi 应用程序图标可以是在 xxhdpi 设备的启动器上使用.

<小时>

更新 #3

请注意,Android Studio 在 mipmap... 文件夹而不是 drawable... 文件夹中创建 ic_launcher.png 图标Eclipse 用于在其中创建它们.

<小时>

解决方案

mipmap 有两种不同的用途:

  1. 用于构建特定于密度的 APK 时的启动器图标.一些开发人员为每个密度构建单独的 APK,以减小 APK 的大小.但是,某些启动器(随某些设备一起提供,或在 Play 商店中提供)使用比标准 48dp 更大的图标尺寸.启动器使用 getDrawableForDensity 并根据需要缩小而不是放大,因此图标质量很高.例如,在 hdpi 平板电脑上,启动器可能会加载 xhdpi 图标.通过将您的启动器图标放在 mipmap-xhdpi 目录中,它不会像 drawable-xhdpi 目录那样在为 hdpi 设备构建 APK 时被剥离.如果您正在为所有设备构建一个 APK,那么这并不重要,因为启动器可以访问所需密度的可绘制资源.

  2. 来自 4.3 的实际 mipmap API.这个我没用过,也不熟悉.Android 开源项目启动器未使用它,我不知道有任何其他启动器在使用.

Since Android 4.3 (Jelly Bean) we can now make use of the res/mipmap folders to store "mipmap" images.

For example, Chrome for Android stores its icons in these folders instead of the more normal res/drawable folders.

How are these mipmap images different from the other familiar drawable images?

I see that in my manifest, we use the @mipmap/ qualifier, instead of @drawable/, which makes sense given the resource folder name:

<activity
    android:name=".MipmapDemp"
    android:icon="@mipmap/ic_launcher" />


References:

The Android 4.3 APIs document has the following to say:

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().

I don't see anything in there that helps me to understand.


XML Bitmap resources have an android:mipMap property:

Boolean. Enables or disables the mipmap hint. See setHasMipMap() for more information. Default value is false.

This does not apply to launcher icons as far as I can see.


The question was raised on Google Groups (The purpose of resource name "mipmap"?!), to which Romain Guy replied:

It's useful to provide an image at a larger resolution that would normally be computed (for instance, on an mdpi device, Launcher might want the larger hdpi icon to display large app shortcuts.)

I feel like this almost makes sense of it, but not quite.

I'm still inclined to go with Randy Sugianto's follow up:

What are the advantages of this? Is there any guide how to use mipmaps, probably for better launcher icons?


Of course, Wikipedia has a page for "Mipmap", which refers to an older technique invented in 1983, that I can't quite relate to the current Android implementation.


Should we be storing all our app icons in res/mipmap folders these days, and what are the guidelines for these mipmap images?


Update #1

Here's a blog post that tries to explain it a bit.

But the image used in that blog post shows what looks like one file with many logos in it. This is not what I see in Chrome's mipmap folder.

Chrome's mipmap-hdpi folder contains three images. One is the Chrome logo, on its own.

Strangely, it is 72x72, not 48x48 which I would expect to see.

Perhaps that is all there is to this - we just need to keep bigger icons in the mipmap folders?


Update #2

The Android Developers Blog post of 23/10/2014 again confirms the idea of using the mipmap folders for application icons:

When talking about the Nexus 6 screen density, the author writes:

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.


Update #3

Note that Android Studio creates the ic_launcher.png icons in the mipmap... folders rather than the drawable... folders that Eclipse used to create them in.


解决方案

There are two distinct uses of mipmaps:

  1. For launcher icons when building density specific APKs. Some developers build separate APKs for every density, to keep the APK size down. However some launchers (shipped with some devices, or available on the Play Store) use larger icon sizes than the standard 48dp. Launchers use getDrawableForDensity and scale down if needed, rather than up, so the icons are high quality. For example on an hdpi tablet the launcher might load the xhdpi icon. By placing your launcher icon in the mipmap-xhdpi directory, it will not be stripped the way a drawable-xhdpi directory is when building an APK for hdpi devices. If you're building a single APK for all devices, then this doesn't really matter as the launcher can access the drawable resources for the desired density.

  2. The actual mipmap API from 4.3. I haven't used this and am not familiar with it. It's not used by the Android Open Source Project launchers and I'm not aware of any other launcher using.

这篇关于图标的 Mipmap 可绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆