0
点赞
收藏
分享

微信扫一扫

关于Android的Lint检查的一些结果分析


前言


在安卓开发中,Lint可以用来帮助我们检查代码中存在的一些问题,使用方法也很简单,Analyze---Inspect Code





关于Android的Lint检查的一些结果分析_javad



Lint检查完成后,可以在Inspection Results中看到检查结果




关于Android的Lint检查的一些结果分析_android_02




下面总结一些常见的lint问题


主要用于有障碍的人士使用


 正确写法如下,如果你想忽略警告


<ImageView
android:id="@+id/iv_top_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/address"
android:contentDescription="@null"
/>

 2.Keyboard inaccessiable widget,给控件添加了clickable属性,但是没添加focusable,一个控件,如果没有定义focusable(可聚焦的),却定义了是clickable(可点击的),

那么是不能通过键盘访问的。所以,需要添加一个focusable="true"。


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
/>


3.Implied locale in date format




传统写法(根据指定的格式创建SimpleDateFormat对象,会有警告)


dateFormat = new SimpleDateFormat(DATE_DEFAULT_FORMAT);
dateTimeFormat = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT);
dateTimeFormat2 = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT_2);

 修正之后的


dateFormat = new SimpleDateFormat(DATE_DEFAULT_FORMAT,Locale.getDefault);
dateTimeFormat = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT,Locale.getDefault);
dateTimeFormat2 = new SimpleDateFormat(DATETIME_DEFAULT_FORMAT_2,Locale.getDefault);


4.LayoutInflation without a parent,如果我们按照下面的方法填充布局,就会有一个警告

View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_layout, null, false);




为什么会有这个警告呢,因为如果我们传null的话,我们给根布局设置的宽高就会失效


5.Missing commit on Sharepreference editor,获取editor后没有提交。




6.Overlapping items in RelativeLayout:RelativeLayout中的条目可能重叠,



7.Padding and margin symmetry:意思是说左右的padding都要指定,为了对称



8.Using left/right instead of start/end attribute,一般是让我们添加layout_toEndOf,marginStart,drawableStart,


alignParent_End等方法,以便支持从右向左的布局



9.Memory allocations withing drawing code:一般是在onDraw里面创建对象



10.OverDraw:Painting regions more than once


Possible overdraw: Root element paints background @drawable/lavagna_verticale with a 
theme that also paints a background (inferred theme is @android:style/Theme.Holo)


所以while此时不适用,

while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
headerBuilder.add((String) entry.getKey(), (String) entry.getValue());
}


ArrayList<String> list = new ArrayList<String>();

正确写法是去掉后面泛型的类型,就没有警告了


13.Declaration has JavaDoc Problems:

/**
* 移除某个key值已经对应的值
*
* @param key
*/
public static void remove(String key) {
editor.remove(key);
editor.commit();
}



















举报

相关推荐

0 条评论