1.'Missing contentDescription attribute on image' in XML
原因:缺少图片描述,在 ADT 16 开始会抛出这个警告,确保开发者为图片添加内容描述。
解决方法:为图片添加 android:contentDescription="@string/desc" 属性。
2. Buttons in button bars should be borderless
原因:两个 Buttons 放在一个布局里会被判断为按钮栏,需要添加样式取消它的边框。
解决方法: 在 Buttons 上添加属性 style="?android:attr/buttonBarButtonStyle" 。系统提示也可以在按钮的父布局上添加 style="? android:attr/buttonBarStyle" 属性,但是我在线性布局上测试了一下无效,求高手指导!
例如:
在android开发中定义一个普通的Button控件,控件会显示Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?android:attr/buttonBarStyle on the parent)的警告信息。
如下所示:
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txtsave" />
解决办法:
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonStyle"
android:text="@string/txtsave" />
添加上面style="?android:attr/buttonStyle"即可去除警告信息,这个属性有很多,可以根据具体需要进行修改
android 布局文件常见错误:
1、报错:Set android:baselineAligned="false" on this element for better performance
如果LinearLayout被用于嵌套的layout空间计算,它的android:baselineAligned属性应该设置成false,以加速layout计算;
2、报错:android:baselineAligned="false"
This LinearLayout layout or its RelativeLayout parent is useless
多余的Linearlayout或者RelativeLayout删除即可;
3、报错:This tag and its children can be replaced by one <TextView/> and a compound drawable
有时候我们可能会用image+textview组合,但其实image是没必要的,textview提供了一个属性来给它设置image;
4、报错:android:drawable="@drawable/resource"
Use a layout_height of 0dip instead of wrap_content for better performance
当在一个linearlayout布局中为一个控件设置weight属性时,这个组件会默认填充剩余空间,去掉weight属性或者修改wrap_content为0dp;