当前位置: 移动技术网 > 移动技术>移动开发>Android > Android——Android lint工具项目资源清理详解

Android——Android lint工具项目资源清理详解

2019年07月24日  | 移动技术网移动技术  | 我要评论

android——android lint工具项目资源清理

最近维护的项目已经有两年多,经过很多前辈的迭代,项目并没有变得健壮,而变得很臃肿.用android lint工具清理了一次,清楚了不少废弃的布局和资源.

1.     android lint工具

可以右键项目,android tools,退出的时候clear lint markers即可


也可以如图:


2.结果出来了,分析分析


3.xml中view太多,已经超过了80个,影响性能.

布局优化:

尽量使用include、merge、viewstub标签,尽量不存在冗余嵌套及过于复杂布局,尽量使用gone替换invisible,使用weight后尽量将width和heigh设置为0dp减少运算,item存在非常复杂的嵌套时考虑使用自定义item view来取代,减少measure与layout次数等。

 列表及adapter优化;尽量复用getview方法中的相关view,不重复获取实例导致卡顿,列表尽量在滑动过程中不进行ui元素刷新等。

背景和图片等内存分配优化;尽量减少不必要的背景设置,图片尽量压缩处理显示,尽量避免频繁内存抖动等问题出现。

自定义view等绘图与布局优化;尽量避免在draw、measure、layout中做过于耗时及耗内存操作,尤其是draw方法中,尽量减少draw、measure、layout等执行次数。 

避免anr,不要在ui线程中做耗时操作,遵守anr规避守则,譬如多次数据库操作等。

activity_group_number_detail1.xml has more than 80 views, bad for performance

issue: checks whether a layout has too many views

id: toomanyviews

using too many views in a single layout is bad for performance. consider using compound drawables or other tricks for reducing the number of views in this layout.


4.没有定义的id,删掉就ok

he id "top" is not defined anywhere.

issue: checks for id references in relativelayouts that are not defined elsewhere

id: unknownid


5.同一个xml重复定义id

在同个一个xml文件的中如果id同名,则前一个有效,而后一个无效

是不是复制粘贴的时候出错了?

duplicate id @+id/group_imageview2, already defined earlier in this layout

issue: checks for duplicate ids within a single layout

id: duplicateids


6.id的引用不在同一级layout中,比如说:控件a在b(b是viewgroup)的下面,而不应该写成a在b的子控件下面.



7.废弃的四大组件,在mainfest.xml中没有清掉.删除就ok

class referenced in the manifest, com.baidu.location.f, was not found in the project or the libraries

issue: ensures that classes referenced in the manifest are present in the project or libraries

id: missingregistered


8.没使用的资源,这是重头戏,对于减小包的大小很有意义.其中包含了xml,dimens等.量比较大,建议先提交svn之后再删除,如果出了问题立马可以还原.

the resource r.drawable.fc_seekbar_thumb appears to be unused

issue: looks for unused resources

id: unusedresources

9.这里检测的结果只是提供一种参考,建议用toast.length_short或者 toast.length_long


10.硬编码的问题,使用context.getfilesdir().getpath()

do not hardcode "/data/"; use context.getfilesdir().getpath() instead

issue: looks for hardcoded references to /sdcard

id: sdcardpath

your code should not reference the /sdcard path directly; instead use environment.getexternalstoragedirectory().getpath().


11.大家一看就懂了,viewholder的问题



12.handler导致的内存泄漏问题

一两句话说不清,下面是已经说清楚的.

http://blog.csdn.net/lijunhuayc/article/details/47999931


13.webview的父控件,宽高建议用match_parent

提示

  placing a <webview> in a parent element that uses a wrap_content layout_height can lead to subtle 
 bugs; use match_parent instead  

14.i18n的问题就不说了.

总结:android lint工具主要功能是规范编码,优化布局性能,去除无用资源.

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!


如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网