在Android应用获取消息:二进制XML文件行#2:你必须提供一个layout_width属性 [英] Getting message in android app: Binary XML file line #2: You must supply a layout_width attribute

查看:127
本文介绍了在Android应用获取消息:二进制XML文件行#2:你必须提供一个layout_width属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个RelativeLayout的内部一个ListView但是当我运行我的应用程序我得到消息一个RuntimeException:

二进制XML文件行#2:你必须提供一个layout_width属性

我试图把layout_width属性在每一个可以想象的地方在XML资源文件,但到目前为止没有运气。

我试图用这条线code来填充列表视图:

  setListAdapter(新ArrayAdapter(这一点,
           R.layout.tablerow3,R.id.label,
           项));

这里的tablerow3.xml内容:

 <?XML版本=1.0编码=UTF-8&GT?;
 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
          机器人:layout_width =20dp
          机器人:layout_height =5DP
          机器人:ID =@ + ID / tablerow01>
      <标签的android:ID =@ + ID / LABEL01
      机器人:layout_width =5DP
  机器人:layout_height =5DP
      机器人:文字颜色=@彩色/ solid_white
         机器人:单线=真/>
      <标签的android:ID =@ + ID / label02
      机器人:layout_width =5DP
  机器人:layout_height =5DP
         机器人:文字颜色=@彩色/ solid_white
         机器人:单线=真/>
      < / LinearLayout中>

下面是包含RelativeLayout的(forex2.xml)的XML:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
   <按钮的android:文本=静态按钮
      机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:ID =@ + ID / button_id>
      < /按钮>        <微调机器人:ID =@ + ID / spinner1
            机器人:layout_width =match_parent
            机器人:layout_toRightOf =@ ID / button_id
            机器人:layout_alignParentTop =真
            机器人:layout_height =WRAP_CONTENT
            机器人:drawSelectorOnTop =真        />    < ListView的机器人:ID =@机器人:ID /列表
 机器人:layout_width =5DP
  机器人:layout_height =5DP
  机器人:layout_alignParentBottom =真
   />
   !< - 机器人:layout_width =WRAP_CONTENT
  机器人:layout_height =WRAP_CONTENT - >
< / RelativeLayout的>


解决方案

该错误是在这里:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
      机器人:layout_width =20dp
      机器人:layout_height =5DP
      机器人:ID =@ + ID / tablerow01>

看,与LinearLayout中开始的行的结尾。你离开一个>用于关闭标签,这意味着遵循由XML解析器作为文本块,该标签的LinearLayout儿童治疗的属性。只是删除额外>,你会没事的。

I'm trying to use a ListView inside of a RelativeLayout but when I run my app I get a runtimeexception with the message:

Binary XML file line #2: You must supply a layout_width attribute.

I tried putting layout_width attributes in every conceivable place in the xml resource files but so far no luck.

I attempt to populate the listview with this line of code:

   setListAdapter(new ArrayAdapter(this,
           R.layout.tablerow3, R.id.label,
           items));

Here's the tablerow3.xml contents:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
          android:layout_width="20dp"
          android:layout_height="5dp"
          android:id="@+id/tablerow01">
      <Label android:id="@+id/label01"
      android:layout_width="5dp"
  android:layout_height="5dp"
      android:textColor="@color/solid_white"
         android:singleLine="true"/>
      <Label android:id="@+id/label02"
      android:layout_width="5dp"
  android:layout_height="5dp"
         android:textColor="@color/solid_white"
         android:singleLine="true"/>
      </LinearLayout>

Here's the xml that contains the RelativeLayout(forex2.xml):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   <Button android:text="Static Button"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:id="@+id/button_id">
      </Button>

        <Spinner android:id="@+id/spinner1"
            android:layout_width="match_parent"
            android:layout_toRightOf="@id/button_id"
            android:layout_alignParentTop="true"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"

        />

    <ListView android:id="@android:id/list"  
 android:layout_width="5dp"
  android:layout_height="5dp"
  android:layout_alignParentBottom="true"
   />
   <!--  android:layout_width="wrap_content"
  android:layout_height="wrap_content" --> 
</RelativeLayout>

解决方案

The bug is here:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
      android:layout_width="20dp"
      android:layout_height="5dp"
      android:id="@+id/tablerow01">

Look at the end of the line that starts with LinearLayout. You left a > which closes the tag, which means the attributes that follow are treated by the XML parser as a block of text, child of the LinearLayout tag. Just remove that extra > and you'll be fine.

这篇关于在Android应用获取消息:二进制XML文件行#2:你必须提供一个layout_width属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆