最近遇到了一个很棘手的问题,原来的项目是在eclipse中写的,迫于google的强大压力,最近把项目转到了android studio(as)下,然后在新增加功能时发现: 只要主view中包含listview, viewpager等可以滑动的控件,主view的background属性就不能用以前的背景图(全屏图片,jpg格式),不用什么事没有,一用就卡的不要不要的,网上问了好多人,都没有这个问题,后来就自己一点一点尝试,排查,终于在N多天后找到原因:
如果背景图放在darwable文件夹下,就会狂卡; 改放在mipmap-hdpi下,问题消失!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
为此,我特意查了google官方解释:
<pre id="recommend-content-2209489229" class="recommend-text mb-10" style="margin-top:0px; margin-bottom:10px; padding:0px; font-family:arial,'courier new',courier,宋体,monospace,'Microsoft YaHei'; white-space:pre-wrap; word-wrap:break-word; font-size:14px; color:rgb(51,51,51); line-height:24px; background-color:rgb(243,255,236)" name="code"><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:rgb(20,25,30); font-family:'Microsoft Yahei','Hiragino Sans GB',Helvetica,'Helvetica Neue',微软雅黑,Tahoma,Arial,sans-serif; font-size:14px; line-height:24.6399993896484px">drawable/</p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:rgb(20,25,30); font-family:'Microsoft Yahei','Hiragino Sans GB',Helvetica,'Helvetica Neue',微软雅黑,Tahoma,Arial,sans-serif; font-size:14px; line-height:24.6399993896484px">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.</p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:rgb(20,25,30); font-family:'Microsoft Yahei','Hiragino Sans GB',Helvetica,'Helvetica Neue',微软雅黑,Tahoma,Arial,sans-serif; font-size:14px; line-height:24.6399993896484px">mipmap/</p><p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:rgb(20,25,30); font-family:'Microsoft Yahei','Hiragino Sans GB',Helvetica,'Helvetica Neue',微软雅黑,Tahoma,Arial,sans-serif; font-size:14px; line-height:24.6399993896484px">For app launcher icons. The <a target=_blank href="http://lib.csdn.net/base/android" class="replace_word" title="Android知识库" target="_blank" style="color:#df3434; font-weight:bold;">Android</a> 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.</p>
上边说的很清楚所有应用图片都可以放在darwnable里,正常调用没问题
但是,如果你的图片比较大,或者需要适配,显然放在mipmap里更合适,因为google对这个文件夹下的图片进行了加工,提高了图片质量,提高了系统渲染图片的速度,同时还减轻了GPU的压力,使用普通图片是感受不到这种优化的,但在极限情况下这个作用就非常巨大了
综上:google强烈推荐用mipmap不是没道理的,大图,高清力尽量都放在这里,不会吃亏,当然,这类图引用的时候也要尽量避免直接使用background,最好用image,src方式