android studio lint基本解析

可访问性(accessibility)

1、Image without contentDescription图像没有内容描述

这个是需要对图片进行一个描述,不然会有警告,一般情况下进行统一的标识加入

android:c ontentDescription="@string/abc

正确性(correctness)

2、Attribute unused on older versions 旧版本中未使用的属性

3、Class is not registered in the manifest 类没有在清单中注册

没有注册的activity

4、Duplicate ids across layouts combined with include tags布局中重复的ids与包含标签相结合

引用的布局和父布局包含相同的id

5、Implied locale in date format 使用日期格式的默示语言环境

http://blog.csdn.net/revival_liang/article/details/51812723

时间声明问题

SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH时mm分ss秒");//有报警问题 SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH时mm分ss秒", Locale.getDefault());

6、Incorrect order of elements in manifest 清单中元素的顺序不正确

有些权限需要写道application之前,示例极光的一个权限

<uses-permission android:name="packagename.permission.JPUSH_MESSAGE" />

7、Layout Inflation without a Parent 父布局没有膨胀

示例 使用null
View view = inflater.inflate(R.layout.progressbar, null);

正确的使用 第三个参数设置为了true,表示将第一个参数所指定的布局添加到第二个参数的View中

LinearLayout ll = (LinearLayout) findViewById(R.id.ll); LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.linearlayout, ll,true);

8、Missing commit() calls 失踪的commit()调用

一般报错

After creating a FragmentTransaction, you typically need to commit it as well

fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.xxxx, new xxxxFragment().newInstance(xxxx),"xxxx"); fragmentTransaction.commit(); 改为(暂未测试效果) fragmentManager.beginTransaction().replace(R.id.xxxx, new xxxxFragment().newInstance(xxxx),"xxxx").commit();

9、Missing commit() on SharedPreference editor

`
SharedPreferences.Editor edit = sp.edit();

edit.putString("isFirstLogin", "0");

edit.commit();

改为 apply()

`
这两个方法的区别在于:

  1. apply没有返回值而commit返回boolean表明修改是否提交成功
  2. apply是将修改数据原子提交到内存, 而后异步真正提交到硬件磁盘, 而commit是同步的提交到硬件磁盘,因此,在多个并发的提交commit的时候,他们会等待正在处理的commit保存到磁盘后在操作,从而降低了效率。而apply只是原子的提交到内容,后面有调用apply的函数的将会直接覆盖前面的内存数据,这样从一定程度上提高了很多效率。
  3. apply方法不会提示任何失败的提示。
    由于在一个进程中,sharedPreference是单实例,一般不会出现并发冲突,如果对提交的结果不关心的话,建议使用apply,当然需要确保提交成功且有后续操作的话,还是需要用commit的。

10、Nested scrolling widgets 嵌套滚动窗口小部件

scrollview中嵌套了listview

11、Obsolete Gradle Dependency 过时Gradle依赖

提示android 升级高版本

12、RecyclerView Problems recycleerview的问题

在onBindviewholder方法中不能使用position 应该使用holer.getAdapterPosition()来获取position 有时候在做item换位置时直接使用postiion会发生位置错误 无法获取到变换后的位置

13、ScrollView size validation scrollview大小的验证

ScrollView里的LinearLayout的高度应该使用wrap_content

14、Reference to an id that is not in the current layout 引用不在当前布局内的id

15、Target SDK attribute is not targeting latest version 目标SDK属性不是针对最新版本的

15、Unreachable state in a <selector>

In a selector, only the last child in the state list should omit a state qualifier. If not, all subsequent items in the list will be ignored since the given item will match all

在选择器中,只有状态列表中的最后一个子应该省略一个状态限定符。如果没有,则列表中的所有后续项都将被忽略,因为给定的项将匹配所有项

16、Using deprecated resources 过时的方法

17、Using inlined constants on older versions quanxu

Internationalization 国际化

18、Hardcoded text 硬编码

https://toutiao.io/posts/572671/app_preview

19、TextView Internationalization

java 代码中使用的汉字应使用常量来代替(个人建议)

20、 Bidirectional Text 双向设置

如 :
android:paddingLeft="15dp"
需要设置两侧对应
android:paddingLeft="15dp" android:paddingRight="15dp"

Performance 性能

21、FrameLayout can be replaced with <merge> tag FrameLayout可以替换为<merge>标签 MergeRootFrame

如果FrameLayout是根布局,并且不提供背景或填充等,它通常可以替换为稍微更有效的<merge>标签。请注意,这取决于上下文,因此请确保在继续之前了解<merge>标记的工作原理。

22、Handler reference leaks handle引起程序泄露参考

因为同一个线程下的handler共享一个looper对象,消息中保留了对handler的引用,由于Java在生成内部类的时候,原本没有构造器的内部类会被生成一个带外部类参数的构造器,这个内部类就会持有外部类的隐式引用。Handler其实隐式的持有了Activity的引用,只要有消息在队列中,那么handler便无法被回收,如果handler不是static那么使用Handler的Service和Activity就也无法被回收。这就可能导致内存泄露

http://blog.csdn.net/liangchengfeng/article/details/51999882

23、HashMap can be replaced with SparseArray HashMap可以用SparseArray替换

`
HashMap<Integer, HashMap<String, String>> rightPopCommonList = new HashMap<Integer, HashMap<String, String>>();
改为
HashMap<Integer, HashMap<String, String>> rightPopCommonList = new new HashMap<>();

`

24、Inefficient layout weight 低效的权重布局

在 设置权重属性的时候相应的宽高属性应设为0dp

25、Layout hierarchy is too deep 布局层次结构太深

嵌套过多的布局不利于性能。考虑使用更平的布局(比如相对布局或GridLayout)。默认的最大深度为10,但可以使用环境变量androidlintmaxdepth配置

26、Memory allocations within drawing code 绘制代码内的内存分配

Avoid object allocations during draw/layout operations (preallocate and reuse instead)
You should avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations. The way this is generally handled is to allocate the needed objects up front and to reuse them for each drawing operation. Some methods allocate memory on your behalf (such as Bitmap.create), and these should be handled in the same way.

27、Missing baselineAligned attribute 消失的baselineAligned属性

baselineAligned属性默认为true 这是基准线设置,设置为fale时它的子控件不对齐
当linearlayout为水平时设置为fale 获取更好的性能
http://blog.csdn.net/bdmh/article/details/48495583

28、Nested layout weights 嵌套布局权重

避免权重套权重,当一个非零权重的线性布局被嵌套在另一个带有非零权重的线性布局中,那么度量的数量就会呈指数增长。

29、Node can be replaced by a TextView with compound drawables 节点可以用一个带有复合绘图的TextView来替换

让只有图片和文字的一个小布局合并为一个textview 这个视情况。

30、Obsolete layout params 布局中无用的参数

31、Overdraw: Painting regions more than once 过度绘制

一般布局根背景不需要在设置bg了 子布局的背景挡住的父布局造成了过度绘制

32、Static Field Leaks 静态变量泄露

主要是上下文对象不要设置为static

33、Unused resources 无用的资源

34、Useless leaf layout 无用的布局

35、Useless parent layout无用的父布局

36、View Holder Candidates adapter没有重用子布局

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值