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,删掉就okhe 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中没有清掉.删除就okClass 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工具主要功能是规范编码,优化布局性能,去除无用资源.
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!