美文网首页AndroidAndroid精选Android开发经验谈
Android Studio的图片到底是放在drawable还是

Android Studio的图片到底是放在drawable还是

作者: 才兄说 | 来源:发表于2017-08-02 18:15 被阅读3456次

从事Android 开发的工程师们一直以为都在讨论一个问题,那就是图片到底应该放在android Studio软件drawable文件夹下,还是应该放在mipmap下?今天把网络上出现的讨论做一个小小的梳理,如果哪里不正确还请指正,文章中会引用一些其他博客的字段,在文章的末尾都会把转载的地址附上。

支持drawable的朋友们的理论出处如下:
谷歌官方:

drawable/
    For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.
mipmap/
     For app launcher icons. The Android system retains the resources in this folder (and 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 Launcher Icons as mipmap Resources.

认为图片放在drawable文件夹下,分为几个不同分辨率的文件夹,而app
icons 放在mipmap下,而且mipmap只放mipmap。

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

认为图片应该放在mipmap文件夹下,理由就是那句标红的英文文字。

那图片到底应该哪个文件夹下呢?有问题找stackoverflow 。

我们可以看到这样的提问,问题是:I’m working with android studio 1.1 Preview 1 我使用android studio 1.1 Preview 1版本工作。 And I noticed that when I create a new project I’m getting next hierarchy: 我注意到当创建新的工程时,得到了下面的目录层级:


mipmap folders for diffrent DPIs, No more diffrent DPIs drawable folders. 4个不同分辨率的mipmap文件夹,与不同DPI的drawable文件夹没啥区别。 Should I put all my resources in the mipmap folders, or just the app icon? 我应该把所有资源都放到mipmap文件夹么?或者只放应用的图标?
答案:The mipmap folders are for placing your app icons in only. Any other drawable assets you use should be placed in the relevant drawable folders as before. mipmap文件夹只放应用图标。其他需要使用的drawable资源象之前一样放到对应的drawable文件夹。

答案的出处来自Google的博文:

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文件夹),因为它们用在不同分辨率的设备上。

回答截图如下:



至于支持图片放在mipmap下的朋友们,应该看看一下截图,相信就会明白到底图片放在哪个文件夹。



综上:图片应该放在drawable文件夹下,而mipmap文件夹只适合放app icons ,之前Android Studio 1.1版本的时候app icons上上传几个不同分辨率的图片,而现在Android Studio 2.1.2 已经把mipmap文件夹默认分为了不同分辨率的文件夹,方便适配。

相关文章

网友评论

  • 清明捉鬼:我观点不同mipmap叫纹理图,谷歌明确表示放一张启动图标在里面最合适,因为它会自动优化自动缩放,放其它图片顶多消耗掉计算资源,我图标一贯放mipmap,我只用纹理图。
  • f6af84f9ec03:怎么把图片放到mipmap下,求指点
    才兄说:如果没有mipmap文件夹,可以按照drawable的格式新建,然后把图片放进去即可。一般AS默认新建项目时会有这个文件夹,以前旧的eclipse项目可能没有,旧的项目直接按照之前的drawable用法即可。
  • 付凯强:你可以自己写一套博文来阐述,但是不建议你直接完全copy,你觉得呢?
  • Love零O:drawable必须新建其他分辨率的文件夹吗?比如drawable-xhdpi,drawable-xxhdpi
    xyyou123:要建啊,高分辨率显示低hdpi 的图片,内存会成倍数增长,而且效果也会模糊
    才兄说:@Love零O 不是必要,多个文件夹只是图片适配需要,不过一般情况最好建,基本都会涉及到图片适配的问题
  • fjutlxl:studio的工具有吗?都没看到网站下载
    才兄说:@fjutlxl http://www.android-studio.org/看看这个地址可以下载?这就是百度的,怎么会没有呢
    fjutlxl: @天鬼 对头,官方过不去
    才兄说:@fjutlxl 怎么网上找不到?
  • icoo:我知道的是 mipmap下的图片系统会优化,drawable下不会优化,小图标都放到mipmap下,大图,.9图,xml文件放在drawable下
    pgydbh:@kuer_ 我有些同意你的看法,如果放一张大图在drawable中,加载时候很卡
    icoo:@kuer_ 你看这篇文章的结论,mipmap只适合放图标,不适合放大图
    kuer_:你说的没错,drawable是不会优化,但是为什么你不把大图也放进mipmap进行优化

本文标题:Android Studio的图片到底是放在drawable还是

本文链接:https://www.haomeiwen.com/subject/maeylxtx.html