【发布时间】:2012-03-02 14:55:52
【问题描述】:
抱歉,因为我的标题与 * 上的许多其他人相似,但这些解决方案都没有解决我的问题。
我正在设计一个使用Relative Layout 的布局。在代码视图中设计后,当我切换到图形视图时,Eclipse 会注意到:
您必须提供一个 layout_width 属性。
您必须提供 layout_height 属性。
。当我运行这个程序时,会注意到 LogCat 中的错误
引起:java.lang.RuntimeException:二进制 XML 文件第 2 行:您 必须提供 layout_width 属性。
这是我的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/contact_name"
android:text="Sam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textSize="20dp"/>
<TextView
android:id="@+id/contact_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="39256493"
android:layout_below="@+id/contact_name"
android:layout_alignLeft="@+id/contact_name"
android:layout_marginTop="5dp"/>
</RelativeLayout>
【问题讨论】:
-
那个 XML 看起来是正确的 - 这是你唯一的布局 XML 吗?检查其他以确保错误不在其中。
-
我遇到了同样的错误。如果您的 xml 布局格式不正确,您可能会收到此错误。在我更正布局中的无效 xml 标签后,它起作用了。 hth!
标签: android xml layout android-relativelayout