android - 用于图标的 Mipmap 可绘制对象

标签 android android-drawable mipmaps

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

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

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

我看到在我的 list 中,我们使用 @mipmap/ 限定符,而不是 @drawable/,考虑到资源文件夹名称,这很有意义:

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

引用资料:

Android 4.3 APIs文件有以下内容:

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

我没有看到任何可以帮助我理解的内容。


XML Bitmap resources有一个 android:mipMap 属性:

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

据我所知,这不适用于启动器图标。


这个问题是在 Google 网上论坛 ( The purpose of resource name "mipmap"?! ) 上提出的,Romain Guy 回复道:

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

我觉得这几乎是有道理的,但并不完全。

我仍然倾向于 Randy Sugianto 的后续行动:

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


当然,Wikipedia has a page for "Mipmap" ,它指的是 1983 年发明的一种较旧的技术,我与当前的 Android 实现不太相关。


这些天我们是否应该将所有应用程序图标存储在res/mipmap文件夹中,这些mipmap图像的指南是什么?


更新 #1

这是一篇试图解释它的博客文章。

但该博客文章中使用的图片显示了一个文件,其中包含许多 Logo 。这不是我在 Chrome 的 mipmap 文件夹中看到的。

Chrome 的 mipmap-hdpi 文件夹包含三个图像。一个是单独的 Chrome Logo 。

Chrome mipmap-hdpi icon.png

奇怪的是,它是 72x72,而不是我希望看到的 48x48。

也许这就是全部 - 我们只需要在 mipmap 文件夹中保留更大的图标?


更新 #2

2014 年 10 月 23 日的 Android 开发者博客文章再次确认了使用 mipmap 文件夹作为应用程序图标的想法:

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

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.


更新 #3

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


最佳答案

mipmap 有两种不同的用途:

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

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

关于android - 用于图标的 Mipmap 可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23935810/

相关文章:

android - 如何覆盖 Android Spinner 上的 onClick?

android - 如何使用 Button 更改 TextView

android - 可在 Android 中为 View 绘制边框,在左侧或右侧留有边距

android - 需要 Android 布局 ID 参数的文档说明

android-studio - 如何一次删除对应的mipmap图标图片?

android - 在 api 26+ 中使用自适应图标的正确方法

android - 在Android studio中为另一个项目添加项目依赖

java - 我需要扩展到fragment 还需要listactivity

android - 二进制 XML 文件第 1 行 : invalid drawable tag vector

javascript - generateMipmap 完成了吗?