Mipmap drawables for icons Ask Question

Mipmap drawables for icons Ask Question

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.

Chrome ミップマップ HDPI アイコン.png

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

2014 年 10 月 23 日の Android Developers Blog の投稿では、mipmapアプリケーション アイコンにフォルダーを使用するというアイデアが再度確認されています。

Nexus 6 の画面密度について、著者は次のように書いています。

アプリ アイコンはデバイスの現在の密度とは異なる解像度で使用されるため、mipmap- フォルダー (drawable- フォルダーではない) に配置するのがベスト プラクティスです。たとえば、xxxhdpi アプリ アイコンは、xxhdpi デバイスのランチャーで使用できます。


アップデート#3

Android Studio は、 Eclipse がアイコンを作成するために使用したフォルダーではなく、フォルダーic_launcher.png内にアイコンを作成することに注意してください。mipmap...drawable...


ベストアンサー1

ミップマップには 2 つの異なる用途があります。

  1. 密度固有の APK を作成する場合のランチャー アイコン用。開発者の中には、APK サイズを小さく保つために、密度ごとに別々の APK を作成する人もいます。ただし、一部のランチャー (一部のデバイスに同梱されているか、Play ストアで入手可能) は、標準の 48dp よりも大きなアイコン サイズを使用します。ランチャーは getDrawableForDensity を使用し、必要に応じて拡大ではなく縮小するため、アイコンは高品質になります。たとえば、hdpi タブレットでは、ランチャーは xhdpi アイコンを読み込む場合があります。ランチャー アイコンを mipmap-xhdpi ディレクトリに配置すると、hdpi デバイス用の APK を作成するときに drawable-xhdpi ディレクトリのようにアイコンが削除されることはありません。すべてのデバイス用に単一の APK を作成している場合、ランチャーは目的の密度の描画可能リソースにアクセスできるため、これはあまり問題になりません。

  2. 4.3 からの実際のミップマップ API。私はこれを使用したことがなく、よく知りません。これは Android オープンソース プロジェクトのランチャーでは使用されておらず、他のランチャーでも使用されているとは知りません。

おすすめ記事