0

我在Button视图上收到此错误。从我在 SO 上看到的许多问题来看,当您没有正确关闭视图时,似乎会出现此错误。

我想我已经正确关闭了所有标签,但仍然收到此错误。这是为什么?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <Button 
        android:layout_width="wrap_content"
        android:layout:height="wrap_content"
        android:text="@string/mainActivity_button1"
        android:onClick="startSecondActivity" />

</RelativeLayout>
4

3 回答 3

2

属性名称中有一个附加/错字:

代替

android:layout:height

android:layout_height

该错误不仅与未关闭的标签有关,而且通常与 XML 语法问题有关。在 XML 中,一个属性只能有一个命名空间前缀,命名空间前缀与名称之间用 . 分隔:

于 2014-11-19T13:14:12.983 回答
2
<Button 
        android:layout_width="wrap_content"
        android:layout:height="wrap_content"
        android:text="@string/mainActivity_button1"
        android:onClick="startSecondActivity" />

替换 : 在属性名称中。

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/mainActivity_button1"
    android:onClick="startSecondActivity" />
于 2014-11-19T13:16:34.187 回答
1

它在这一行的当然错字:

android:layout:height="wrap_content"

将上面的行替换为:

android:layout_height="wrap_content"
于 2014-11-19T13:31:59.890 回答