toLeftOf资源未找到

Ran*_*and 3 xml android android-layout

我以前曾经多次使用过LeftOf但它突然停止工作了.我试过了:

android:layout_toLeftOf="@id/spacer"
Run Code Online (Sandbox Code Playgroud)

这是观点:

<View
    android:id="@+id/spacer"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginLeft="@dimen/center_margin"
    android:layout_marginStart="@dimen/center_margin"
    android:layout_marginRight="@dimen/center_margin"
    android:layout_marginEnd="@dimen/center_margin" />
Run Code Online (Sandbox Code Playgroud)

它给了我错误:

Error:(16, 34) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/spacer').
Error:(17, 35) No resource found that matches the given name (at 'layout_toStartOf' with value '@id/spacer').
Run Code Online (Sandbox Code Playgroud)

它适用于应用程序中的其他点,但由于某种原因它在这里不起作用.谁知道什么是错的?

编辑 - 是的,它位于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"
android:screenOrientation="portrait"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true" >

<TextView
    android:id="@+id/txt1" />

<View
    android:id="@+id/spacer" />

<TextView
    android:id="@+id/txt2" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Ran*_*and 17

经过进一步的审查,我发现问题是我试图在它制作之前引用它.我通过将@ id/spacer更改为@ + id/spacer来修复此问题