LoginSignup
128
124

More than 5 years have passed since last update.

Androidのmipmapとdrawableについて

Last updated at Posted at 2015-04-09

以前はdrawable-xxxxxというディレクトリに解像度ごとの画像を用意することでマルチ解像度対応ができていたのですが、いつのまにかmipmap-xxxxxというのもあるようなので調べてまとめておきました。

概要

概要説明はAndroid4.3の説明にありました。
https://developer.android.com/about/versions/android-4.3.html#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().

ここから読み取れるのは、

  • Android4.2から使用できる
  • mipmapイメージを使うと、旧来のdrawableが画面解像度に応じたbitmapイメージを選択してロードしてくれていた仕組みに対して、拡大縮小アニメーションをしたときにも適切なビットマップを適用してくれる。
    • 旧来の仕組みはリソース節約のための仕組みだったのに対して、新しい仕組みは、メモリやGPU等がリッチになった前提でインタラクションを優先した仕組みな模様。
  • mipmapを使用するには新しいAPIを使用する。(従来のdrawableの使い方で勝手にmipmapイメージを選択してくれたり、置き換わったりするわけではないようだ。)

また、こちらも参考になりました。
https://plus.google.com/109167540865998371620/posts/U9TLZ65yJ6S
http://qiita.com/operandoOS/items/53b0f2074a806aacd290

マルチスクリーン対応の説明はどう変わったか

Note: Place all your launcher icons in the res/mipmap-[density]/ folders, rather than the res/drawable-[density]/ folders. The Android system retains the resources in these density-specific folders, such as mipmap-xxxhdpi, regardless of the screen resolution of the device where your app is installed. This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen. For more information about using the mipmap folders, see Managing Projects Overview.

Make sure launcher apps show a high-resolution icon for your app by moving all densities of your launcher icons to density-specific res/mipmap/ folders (for example res/mipmap-mdpi/ and res/mipmap-xxxhdpi/). The mipmap/ folders replace the drawable/ folders for launcher icons. For xxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of the icons to enhance the visual experience of the icons on higher resolution devices.

このあたりによると、ランチャーアイコンについてはmipmapに完全に置き換わっているようです。
そのほかの一般的なアプリ内の画像リソースでのdrawableとmipmapの使い分けについては特に記述はありませんでした。

drawableを使うのは今までどおりでよく、拡大縮小が絡むところだけmipmapの使用を検討すればよさそうです。

リソースディレクトリはどうなるか

こちらによると、こんな感じになります。

res/drawable-mdpi/graphic.png         // bitmap for medium-density
res/drawable-hdpi/graphic.png         // bitmap for high-density
res/drawable-xhdpi/graphic.png        // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png       // bitmap for extra-extra-high-density

res/mipmap-mdpi/my_icon.png         // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png         // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png        // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png       // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png      // launcher icon for extra-extra-extra-high-density

また、
http://developer.android.com/guide/practices/screens_support.html#support

    Note: The mipmap-xxxhdpi qualifier is necessary only to provide a launcher icon that can appear larger than usual on an xxhdpi device. You do not need to provide xxxhdpi assets for all your app's images.

アイコンファイルはxxxhdpまで用意してほしいが、それ以外のイメージについては必須ではないとのこと。

理由はちゃんと書いてありませんが、おそらく必須とするとアプリサイズが膨大になるし、大抵の場合はxxhdpiイメージからの拡大でも問題ないという判断なのではないかと思います。

対応OSバージョンごとの選択肢

Android4.1以前では使えないため、対応OSバージョンごとに次の選択肢が考えられます。

最低バージョンがAndroid4.2以上 (android:minSdkVersionが17以上)

  • アイコンはmipmapだけでOK
  • 画像リソースは基本drawable
  • アプリ内で画像の拡大縮小をする場合はmipmapの使用を検討する

最低バージョンがAndroid4.1以前(android:minSdkVersionが16以下)

  • アイコンはdrawableとmipmap両方に用意する
    • またはdrawableだけにしても、互換性はあるはずなので大丈夫
    • でもapkになる時点では圧縮されるので、両方にあっても悪影響は少ないと思う
  • 画像リソースはdrawableに
  • アプリ内で画像の拡大縮小をする場合はmipmapの使用を検討する
    • ただし、その際には必ずAPIレベルのチェックを行ってからAPIを呼ぶ必要があるので煩雑になる覚悟の上で
128
124
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
128
124