lint 总结(未完成)

Android Studio 中使用 Lint
工具栏 -> Analyze -> Inspect Code…

至于lint是什么……请自行百度搜索……
这是总结以往lint是怎么解决黄色警告的,以及原因。
同时分几大类。

1.标签类:

1.1.Element arcMotion is not allowed here

指的是arcMotion该标签不允许。只要在标签前面添加suppress AndroidElementNotAllowed即可

《lint 总结(未完成)》 image.png

1.2.Missing ‘contentDescription’ attribute on image

需要给图片添加备注。
一般来说我选择忽略,添加tools:ignore=”ContentDescription”

1.3.’clickable’ attribute found, please also add ‘focusable’

一个控件(比如图片),如果没有定义focusable(可聚焦的),却定义了是clickable(可点击的),那么是不能通过键盘访问的。所以,需要添加一个focusable=”true”。

1.4.Missing accessibility label: where minSdk < 17, you should provide an ‘android:hint’

意思是要添加hint,如果不想添加hint,那么就选择忽略,添加tools:ignore=”LabelFor”

1.5.”‘xxxx'” is not translated in “zh” (Chinese)

如果一个字符串不需要翻译,可以添加属性translatable=”false”在<string>标签里。如:

<string name="name" translatable="false">Android</string>
或者把你不需要翻译的字符串统一放到一个
donottranslate.xml
中去。或者给根标签加一个属性tools:ignore=”MissingTranslation”来忽略这个问题。

1.6.’A’ can overlap ‘B’ if ‘C’ grows due to localized text expansion

原因:此提示一般出现在RelativeLayout中,此提示的大体意思为:你某个布局(一般是TextView,因为TextView的长度会随着文本内容扩大而扩大)可能会重叠另外一个布局。
如果还不理解,可以给该textview的文本写上超长内容就能看到问题了~
解决方式如下:
一:确保该文本长度不会覆盖的话,选择忽略。tools:ignore=”RelativeOverlap”
二:使用RelativeLayout的布局属性,设置该textview的长度不会覆盖

1.7.Set ‘android:baselineAligned=”false”‘ on this element for better performance

原因是:当LinerLayout的子View都是ViewGroup(自定义控件除外)时,Lint认为它的子View已经不需要基准线对齐了,为了不让LinerLayout去做无用的计算对齐的操作,提出了如上警告,修改掉之后就可以提高性能。

1.8.Nested weights are bad for performance

原因是:嵌套权重对性能不好
解決方式:使用百分比布局或者约束布局ConstraintLayout或者其他方式,反正就是避免嵌套权重

2.代码类:

2.1.Custom view 'XXXXX' has ‘setOnTouchListener’ called on it but does not override ‘performClick’

这个貌似是从某个版本更新后出现的一个新警告,这个警告是告诉你点击事件会跟OnTocuch事件冲突。
基本上这意味着你应该继承该view的子类重写其performclick()方法,但这是不必要的。在确保有执行OnTouchlistener的情况下,我们只需要抑制这种警告使用@SuppressLint("ClickableViewAccessibility")就可以了。

2.2.This custom view should extend ‘android.support.v7.widget.AppCompatImageView’ instead

extends ImageView 改成 extends android.support.v7.widget.AppCompat
原因:Using AppCompat widgets allows you to have some material design (and other new) features on devices with pre-Lollipop versions of Android.

At this point AppCompatImageView only provides the support for background tint and vector drawables. If you don’t use them, then extending the regular ImageView will be fine.

2.3.Switch statement on an ‘int’ with known associated constant missing case ‘XXXX’, ‘XXX’

指明该swith少了’XXXX’,要么忽略,要么加上。

    原文作者:qq名长是因为你没给我备注
    原文地址: https://www.jianshu.com/p/bb712fc4ab1c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞