XML文档必须在同一个实体内开始和结束才能帮助我

时间:2014-06-10 04:23:30

标签: android xml eclipse

<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="${packageName}.${activityClass}" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"
        tools:context=".MainActivity" >

        <AnalogClock
            android:id="@+id/analogClock1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="290dp" />

        <TextClock
            android:id="@+id/textClock1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="146dp"
            android:text="@+id/textclock"
            android:textColor="#FFFFFF"
            android:textSize="100sp" />

</RelativeLayout>

我可以在这方面得到一些帮助我真的很感到非常欣赏一些建议。出现此错误时,我只是在清理代码。我不知道如何修复

1 个答案:

答案 0 :(得分:0)

错误的发生是因为您没有关闭xml文件中的RelativeLayout标记,因此请在xml文件的末尾添加</RelativeLayout>

您不需要添加两个相对布局,其中一个父布局无效

所以只需在代码中替换

<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="${packageName}.${activityClass}" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"
        tools:context=".MainActivity" >

 <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"
            android:background="@drawable/bg"
            tools:context=".MainActivity" >

第二个选项是 删除xml代码并保存xml file。之后,将其替换为上面的代码并保存。错误将消失。它可能是自动构建项目&#34;启用。