源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-09-05 13:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android——Android lint工具项目资源清理详解
[b]Android——Android lint工具项目资源清理[/b] 最近维护的项目已经有两年多,经过很多前辈的迭代,项目并没有变得健壮,而变得很臃肿.用Android lint工具清理了一次,清楚了不少废弃的布局和资源. [b]1.     Android lint工具[/b] 可以右键项目,Android tools,退出的时候clear lint markers即可 [img]http://files.jb51.net/file_images/article/201611/201611161446261.jpg[/img] 也可以如图: [img]http://files.jb51.net/file_images/article/201611/201611161446262.png[/img] [b]2.结果出来了,分析分析[/b] [img]http://files.jb51.net/file_images/article/201611/201611161446263.jpg[/img] [b]3.xml中view太多,已经超过了80个,影响性能.[/b] [b]布局优化:[/b] 尽量使用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. [img]http://files.jb51.net/file_images/article/201611/201611161446264.jpg[/img] [b]4.没有定义的id,删掉就ok[/b] he id "top" is not defined anywhere. Issue: Checks for id references in RelativeLayouts that are not defined elsewhere Id: UnknownId [img]http://files.jb51.net/file_images/article/201611/201611161446265.jpg[/img] [b]5.同一个XML重复定义id[/b] 在同个一个Xml文件的中如果ID同名,则前一个有效,而后一个无效 是不是复制粘贴的时候出错了? Duplicate id @+id/group_imageView2, already defined earlier in this layout Issue: Checks for duplicate ids within a single layout Id: DuplicateIds [img]http://files.jb51.net/file_images/article/201611/201611161446276.jpg[/img] 6.ID的引用不在同一级layout中,比如说:控件A在B(B是viewgroup)的下面,而不应该写成A在B的子控件下面. [img]http://files.jb51.net/file_images/article/201611/201611161446277.jpg[/img] [img]http://files.jb51.net/file_images/article/201611/201611161446278.jpg[/img] [b]7.废弃的四大组件,在mainfest.xml中没有清掉.删除就ok[/b] 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 [img]http://files.jb51.net/file_images/article/201611/201611161446279.jpg[/img] [b]8.没使用的资源,这是重头戏,对于减小包的大小很有意义.其中包含了xml,dimens等.量比较大,建议先提交SVN之后再删除,如果出了问题立马可以还原.[/b] The resource R.drawable.fc_seekbar_thumb appears to be unused Issue: Looks for unused resources Id: UnusedResources [img]http://files.jb51.net/file_images/article/201611/2016111614462710.jpg[/img] [b]9.这里检测的结果只是提供一种参考,建议用Toast.LENGTH_SHORT或者 Toast.LENGTH_LONG[/b] [img]http://files.jb51.net/file_images/article/201611/2016111614462711.jpg[/img] [img]http://files.jb51.net/file_images/article/201611/2016111614462712.jpg[/img] [b]10.硬编码的问题,使用Context.getFilesDir().getPath()[/b] 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(). [img]http://files.jb51.net/file_images/article/201611/2016111614462813.jpg[/img] [b]11.大家一看就懂了,viewholder的问题[/b] [img]http://files.jb51.net/file_images/article/201611/2016111614462814.jpg[/img] [img]http://files.jb51.net/file_images/article/201611/2016111614462815.jpg[/img] [b]12.handler导致的内存泄漏问题[/b] 一两句话说不清,下面是已经说清楚的. http://blog.csdn.net/lijunhuayc/article/details/47999931 [img]http://files.jb51.net/file_images/article/201611/2016111614462816.jpg[/img] [b]13.webview的父控件,宽高建议用match_parent[/b] 提示   Placing a <WebView> in a parent element that uses a wrap_content layout_height can lead to subtle   bugs; use match_parent instead   [b]14.I18N的问题就不说了.[/b] 总结:Android lint工具主要功能是规范编码,优化布局性能,去除无用资源. 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部