发布于 2017-03-16 02:33:46 | 221 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android——Android lint工具项目资源清理详解的相关资料,需要的朋友可以参考下

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工具主要功能是规范编码,优化布局性能,去除无用资源.

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




最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务