toLeftOf资源未找到

时间:2015-04-24 22:10:47

标签: android xml android-layout

我以前曾多次使用左手,但它突然停止工作。我试过了:

SET fldname='St' WHERE fldname == 'Stats'

以下是观点:

android:layout_toLeftOf="@id/spacer"

它给了我错误:

<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" />

它可以在应用程序的其他位置工作但由于某种原因它在这里不起作用。任何人都知道什么是错的?

编辑 - 是的,它位于RelativeLayout中。这是一个浓缩版本:

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').

4 个答案:

答案 0 :(得分:17)

经过进一步审核,我发现问题是我试图在制作之前引用View。我通过将@ id / spacer更改为@ + id / spacer

来修复此问题

答案 1 :(得分:2)

有点晚了,但也许对其他人有帮助。花了我1个小时才发现我的问题。

非工作示例:

  <TextView
    android:id="@+id/firstview"
    android:layout_toRightOf="@id/secondview"/>

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

工作示例

    <TextView
    android:id="@+id/firstview"
    android:layout_toRightOf="@+id/secondview"/>

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

不是标志“+”是唯一的区别。 如果引用在放置引用的视图之后定义的视图,则需要使用+

答案 2 :(得分:0)

编写用作参考的布局,然后编写相对于该布局要放置的布局......

这就像在同一个类文件中声明之前尝试使用变量一样。

答案 3 :(得分:-1)

您无法引用在各自ViewGroup中找不到的属性。在这种情况下,您尝试访问特定于RelativeLayout的属性。您无法访问这些类型的属性,除非您的封装视图实际上是RelativeLayout。

请注意,这适用于封装视图的Parent布局。