2011-01-12 79 views
2

我试图使用的RelativeLayout内一个ListView但是当我运行我的应用程序我得到消息一个RuntimeException:获得消息:二进制XML文件行#2:你必须提供一个layout_width属性

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

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

我试图与这行代码来填充ListView:

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

这里的tablerow3.xml内容:

<?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> 

这里包含的RelativeLayout(forex2.xml)的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> 

回答

4

的错误是在这里:

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

查看以LinearLayout开头的行的末尾。您留下了一个关闭标签的>,这意味着随后的属性被XML解析器视为LinearLayout标签的子文本块。只要删除额外的>,你会没事的。

+0

谢谢 - 不能相信我错过了。 现在我正在处理下一条错误消息:二进制XML文件行#6:错误使类标签膨胀。 – opike 2011-01-13 00:00:28

1

关于您的评论,标签没有Android小部件。您可能需要一个TextView。

1

这不是您的具体问题的答案,而是相同错误的另一个原因。

我有一个类似的错误,只是我的问题是,我进入的模式,而不是模式

即。

LinearLayout xmlns:android="http://schema.android.com/apk/res/android" // wrong 

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" // correct. 

希望这有助于他人。

相关问题