Android布局文件错误,android 布局文件常见错误

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)的警告信息。

如下所示:

解决办法:

添加上面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 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;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值