You must supply a layout_width layout_width attribute 错误

从字面上解释就是,你必须提供layout_width属性。 layout_width的属性很重要,好多控件和布局都必须写layout_width属性,否则就会报这个错误,所以我们再写布局文件的时候要特别注意这个属性。

今天我写了一个组合控件,如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_setting"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="60dip"
        android:background="#C000BB00"
        android:gravity="center"
        android:text="@string/option9"
        android:textColor="#FFFFFF"
        android:textSize="30sp" />

    <com.example.view.CheckedItemBox
        android:id="@+id/checked_relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </com.example.view.CheckedItemBox>

</LinearLayout>

com.example.view.CheckedItemBox的文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
 >

    <TextView
        android:id="@+id/tv_setautoupdate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dip"
        android:gravity="left"
        android:text="@string/setautoupdate"
        android:textColor="#000000"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/tv_setautoupdateword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_setautoupdate"
        android:layout_marginLeft="2dip"
        android:gravity="left"
        android:text="@string/setautoupdateword"
        android:textColor="#88000000"
        android:textSize="18sp" />

    <CheckBox
        android:id="@+id/cb_setautoupdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dip"
        android:gravity="center_vertical" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:layout_below="@id/tv_setautoupdateword"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="5dip"
        android:layout_marginTop="5dip"
        android:background="#000000" />

</RelativeLayout>
 我在com.example.view.CheckedItemBox类型中加了layout_width的属性,以为和下面的RelativeLayout是一个属性,所以在RelativeLayout没有加,其实CheckedItemBox只是RelativeLayout的父窗体,所以在RelativeLayout也一样得加。 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值